rust - Can struct-like enums be used as types? -
consider following (illegal) example:
enum foo { bar { i: i32 }, baz, } struct mystruct { field: foo::bar, } foo::bar struct-like variant. i've found them quite useful. however, have instance need store instance of struct inside struct, above example of mystruct. changing mystruct::field foo invalid, doesn't make sense field foo::baz. it's meant instance of foo::bar.
rustc tells me above code invalid:
error: found value name used type: defvariant(defid { krate: 0u32, node: 4u32 }, defid { krate: 0u32, node: 5u32 }, true) am doing wrong, or not possible? if it's not possible, there plans on doing it?
i know work around this, consider inferior option , it's 1 i'd avoid if possible:
struct bar { i: i32, } enum foo { bar(bar), baz, } struct mystruct { field: bar, }
in first situation,
enum foo { bar { i: i32 }, baz, } as compiler tells bar not type value, , cannot used type (error: found value name used type).
you second construction used, example in standard library std::net::ipaddr , std::net::socketaddr.
Comments
Post a Comment