If that is all you are using the discriminant for why not just make
struct Foo{
content: FooEnum;
}
Or if that's the only field do you even need the Foo struct at all? Rust allows you to implement methods for enum
also. In general as pointed in the answer to my question here the strategy which I know use, and like more is to put the enum
union as inside as possible in the structs.
Also is there a reason why Bar
and Baz
don't derive Copy
? Would make it nicer rather than using unsafe code, no?
PS: Ok I've just figured out why you need this (because its importing it from a C library), which I did not pay attention before. In that case I think what you are doing is fine. Shouldn't post an answer before breakfast any more!