[−][src]Derive Macro modular_bitfield::prelude::BitfieldSpecifier
#[derive(BitfieldSpecifier)] { // Attributes available to this derive: #[bits] }
Derive macro for enums.
Generates code for enums to make them usable within #[bitfield]
structs.
Performs compile-time checks to validate that the enum is usable as bitfield specifier.
Example
use modular_bitfield::prelude::*; #[bitfield] struct Example { a: bool, // Uses 1 bit b: Mode, // Has 4 variants => uses 2 bits c: B5, // Uses 5 bits d: B24, // Uses 24 bits } #[derive(BitfieldSpecifier, Debug, PartialEq, Eq)] pub enum Mode { Sleep, Awake, Working, Lazy, } let mut example = Example::new(); assert_eq!(example.a(), false); // `false as u8` is 0 assert_eq!(example.b(), Mode::Sleep); example.set_a(true); example.set_b(Mode::Awake); assert_eq!(example.a(), true); // `true as u8` is 1 assert_eq!(example.b(), Mode::Awake);