Macro bitfield::bitfield_struct
[−]
[src]
macro_rules! bitfield_struct { (@impl_bitrange_slice $name:ident, $slice_ty:ty, $bitrange_ty:ty) => { ... }; (@impl_bitrange_slice_msb0 $name:ident, $slice_ty:ty, $bitrange_ty:ty) => { ... }; ($(#[$attribute:meta])* struct $name:ident($($args:tt)*)) => { ... }; ($(#[$attribute:meta])* pub struct $name:ident($($args:tt)*)) => { ... }; ($(#[$attribute:meta])* ($($vis:tt)*) struct $name:ident([$t:ty])) => { ... }; ($(#[$attribute:meta])* ($($vis:tt)*) struct $name:ident(MSB0 [$t:ty])) => { ... }; ($(#[$attribute:meta])* ($($vis:tt)*) struct $name:ident($t:ty)) => { ... }; }
Declares a struct that implements BitRange
,
This macro will generate a tuple struct (or "newtype") that implements the BitRange
trait and
by extension the Bit
trait.
The syntax is more or less the same as declaring a "newtype", including 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
bitfield_struct!{struct BitField1(u32)} bitfield_struct!{ /// The documentation for this type #[derive(Copy, Clone)] pub struct BitField2(u64) } bitfield_struct!{struct BitField3([u8])} bitfield_struct!{struct BitField4(MSB0 [u8])}