Skip to main content

define_header_enum

Macro define_header_enum 

Source
macro_rules! define_header_enum {
    (
        error_type: $Err:ident,
        $(#[$enum_meta:meta])*
        $vis:vis enum $Name:ident {
            $(
                $(#[$var_meta:meta])*
                $variant:ident => $wire:literal
            ),+ $(,)?
        }
    ) => { ... };
}
Expand description

Generates a non-exhaustive enum mapping Rust variants to canonical protocol strings.

Produces: enum definition + as_str() + Display + AsRef<str> + FromStr. FromStr uses eq_ignore_ascii_case — appropriate for user-facing catalog types (header names, variable names) where input may come from config files. Wire protocol state types use hand-written strict FromStr instead. The error type must be defined separately (matching existing crate patterns like ParseEventHeaderError, ParseChannelVariableError).

§Example

define_header_enum! {
    error_type: ParseMyEnumError,
    /// Doc comment for the enum.
    pub enum MyEnum {
        Foo => "foo-wire",
        Bar => "bar-wire",
    }
}