macro_rules! bf {
($($args:tt)*) => { ... };
}Expand description
Declare a bitfield type.
#[macro_use]
extern crate bitutils;
bf!(BitfieldName[u8] {
field1: 0:3, // lower nibble
field2: 4:6,
field3: 7:7
});
let mut bf = BitfieldName::new(0);
bf.set_field3(0xF);
assert_eq!(bf.val, 0x80);
bf.val = 0xF0;
assert_eq!(bf.field1(), 0);
assert_eq!(bf.field2(), 7);
assert_eq!(bf.field3(), 1);This declares a module BitfieldName with the members:
pub struct Bf { pub val: T, pub field1: Field1, pub field2... }pub fn new(val: T) -> Bfpub fn alias(val: &'a T) -> &'a Bfpub fn alias_mut(val: &'a mut T) -> &'a mut Bf
Each field has the impl:
pub fn(&self) -> Tpub set_fn(&mut self, val: T)pub upd_fn(&mut self, func: FnOnce(T) -> T)