Macro bit_struct::enums
source · macro_rules! enums { ( $( $(#[$meta:meta])* $enum_vis: vis $name: ident $(($enum_default: ident))? { $(#[$fst_field_meta:meta])* $fst_field: ident $(, $(#[$field_meta:meta])* $field: ident )* $(,)? } )+ ) => { ... }; }
Expand description
Create enums with trait implementations necessary for use in a bit_struct
field.
Example:
enums! {
pub Colors { Red, Green, Blue }
Shapes { Triangle, Circle, Square }
}
By default, this macro produces an impl of Default
in which the first
field listed is made the default. However, you can also specify some other
variant as the default, as follows:
enums! {
DefaultsToA { A, B, C }
DefaultsToB (B) { A, B, C }
}
assert_eq!(DefaultsToA::default(), DefaultsToA::A);
assert_eq!(DefaultsToB::default(), DefaultsToB::B);