[][src]Macro ethox::enum_with_unknown

macro_rules! enum_with_unknown {
    (
        $( #[$enum_attr:meta] )*
        pub enum $name:ident($ty:ty) {
            $($(#[$val_attr:meta])* $variant:ident = $value:expr ),+ $(,)*
        }
    ) => { ... };
    (
        $( #[$enum_attr:meta] )*
        pub doc enum $name:ident($ty:ty) {
            $(
              $( #[$variant_attr:meta] )+
              $variant:ident = $value:expr $(,)*
            ),+
        }
    ) => { ... };
}

Define an enumeration with known variants and an unknown representation.

Most network protocols define fields where not all bit-patterns are standardized values. In some cases these are invalid while others allocate them through some registrar (such as IANA). This macro makes it more ergonomic to define a representation for such fields by providing converters to and from an underlying representation derived from the definition.

Example

enum_with_unknown! {
    pub enum IpVersion(u8) {
        IpV4 = 4,
        IpV6 = 6,
    }
}