macro_rules! typeenum {
( $(#[$attr:meta])*
$name:ident,
$ty:ty,
{
$($x:expr => $y:ident),+ $(,)*
}
$(,{
$( $x1:pat => $y1:ident ),* $(,)*
})?
) => { ... };
}Expand description
Generate enums for codepoints in protocols.
ยงExample
typeenum!(
AFI, u16,
{
1 => Ipv4,
2 => Ipv6,
25 => L2Vpn
}
);This will create a pub enum AFI, comprised of variants IPv4, IPv6
and L2Vpn. On this enum, the From (for conversion between the
variants and u16) and std::fmt::Display traits are implemented.
You can also specify ranges as like so:
typeenum!(
PeerType, u8,
{
0 => GlobalInstance,
1 => RdInstance,
2 => LocalInstance,
3 => LocalRibInstance,
},
{
4..=250 => Unassigned,
251..=254 => Experimental,
255 => Reserved,
}
);Note that match lines with ranges are come in a separate block after
the block with single selector values. Range variants have a data
field with the specified value. Specifying an half-open range to the
right or specifying the matches exhaustively will disable the default
Unimplemented variant.