Skip to main content

define_enum_u16

Macro define_enum_u16 

Source
macro_rules! define_enum_u16 {
    (
        $(#[$meta:meta])*
        pub enum $Name:ident as $field:literal {
            $( $(#[$vmeta:meta])* $Variant:ident = $val:expr ),* $(,)?
        }
    ) => { ... };
}
Expand description

Generates a fallible u16-backed enum: exhaustive, a to_u16 encoder, and a TryFrom<u16> decoder that rejects every value not listed (E_UNKNOWN_ENUM_VALUE, naming $field — the wire field name, not the Rust type name). No catch-all variant: an unrecognized value is always a decode error, never a value the type can represent.