macro_rules! bitstruct {
{
$(
$( #[$($outter:tt)*] )*
$vs:vis struct $sname:ident : $int:ty {
$(
$fvs:vis $fname:ident: $from:tt..=$to:tt
),*$(,)?
}
)*
} => { ... };
}Expand description
Creates a structure with access to individual bits
memflex::bitstruct! {
pub struct Foo : u8 {
a: 0..=3,
b: 4..=6,
c: 7..=7
}
}
let mut foo = Foo::from_bits(0b_1101_1101);
assert_eq!(foo.a().get(), 0b_1101);
assert_eq!(foo.b().get(), 0b_101);
assert_eq!(foo.c().as_bool(), true);
foo.a_mut().set(0b_0110);
foo.b_mut().set(0b_101);
foo.c_mut().set_bool(false);
assert_eq!(foo.a().get(), 0b_0110);
assert_eq!(foo.b().get(), 0b_101);
assert_eq!(foo.c().as_bool(), false);
assert_eq!(foo.bits(), 0b_0101_0110);