macro_rules! bitfield_bitrange { (@impl_bitrange_slice $name:ident, $slice_ty:ty, $bitrange_ty:ty) => { ... }; (@impl_bitrange_slice_msb0 $name:ident, $slice_ty:ty, $bitrange_ty:ty) => { ... }; (struct $name:ident([$t:ty])) => { ... }; (struct $name:ident(MSB0 [$t:ty])) => { ... }; (struct $name:ident($t:ty)) => { ... }; }
Expand description
Implements BitRange
for a tuple struct (or “newtype”).
This macro will generate an implementation of the BitRange
trait for an existing single
element tuple struct.
The syntax is more or less the same as declaring a “newtype”, without the attributes, documentation comments and pub keyword.
The difference with a normal “newtype” is the type in parentheses. If the type is [t]
(where
t
is any of the unsigned integer type), the “newtype” will be generic and implement
BitRange
for T: AsMut<[t]> + AsRef<[t]>
(for example a slice, an array or a Vec
). You can
also use MSB0 [t]
. The difference will be the positions of the bit. You can use the
bits_positions
example to see where each bits is. If the type is neither of this two, the
“newtype” will wrap a value of the specified type and implements BitRange
the same ways as
the wrapped type.
§Examples
struct BitField1(u32);
bitfield_bitrange!{struct BitField1(u32)}
struct BitField2<T>(T);
bitfield_bitrange!{struct BitField2([u8])}
struct BitField3<T>(T);
bitfield_bitrange!{struct BitField3(MSB0 [u8])}