Skip to main content

emit_enum

Function emit_enum 

Source
pub fn emit_enum(w: &mut CodeWriter, en: &EnumDef, _registry: &TypeRegistry)
Expand description

Emit a complete enum type with Pack and Unpack implementations.

§Non-exhaustive enums

When annotations.non_exhaustive is true, the enum gains an Unknown(u64) catch-all variant. Because Unknown carries data, #[repr(u64)] cannot be used (Rust only allows repr discriminants on fieldless enums). In that case we emit a plain enum and implement the Pack/Unpack trait by hand.

§Exhaustive enums

When the enum is exhaustive every variant is fieldless, so we use #[repr(u64)] to let the compiler verify the discriminant assignments.