Enum 'tags', manually assigned?


#1

would there be any demand to be able to say this sort of thing,

#[repr(u32)]
enum FBB{
     Foo(f32,f32)=0x00000001,
     Bar(f32,f32),
     Baz(String)
}

e.g. to spell out a specific assignment of tags for interoperability with C manually rolled tagged unions / symmetry with binary formats .
(spelling out starting at 0 or 1, or possibly existing uneven assignment of variants that leaves room for adding in the middle)

(I know we seem to have manual assignment for dataless enums)


#2

I’d probably use a Rust untagged union (note: nightly only) and manually implement an equivalent of my enum as a tagged union for the FFI layer. That would probably be more beneficial than what you are proposing because it’s more explicit how things are laid out in memory.

Also, note that #[repr(u32)] is only defined for C-style enums. My understanding is that the annotation means “this entire thing can be represented in memory using a u32”, so having data members like f32 or String wouldn’t make sense because it’d require more room than is available.