devela/examples/data/bitfield.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
// devela::examples::data::bitfield
//
//! Shows how to use the [`bitfield!`] declarative macro.
//
use devela::bitfield;
bitfield! {
(extra)
/// An example created with [`bitfield!`],
/// with public extra methods but no custom fields.
///
/// ```
/// use devela::bitfield;
///
/// bitfield! {
/// (extra)
///
/// /// An example created with [`bitfield!`],
/// /// with public extra methods but no custom fields.
/// pub struct ExampleBitfieldExtra(u8) {}
/// }
/// ```
pub struct ExampleBitfieldExtra(u8) {}
}
bitfield! {
(custom)
/// An example created with [`bitfield!`],
/// with public custom fields but no extra methods.
///
/// ```
/// use devela::bitfield;
///
/// bitfield! {
/// (custom)
///
/// /// An example created with [`bitfield!`],
/// /// with public custom fields but no extra methods.
/// pub struct ExampleBitfieldCustom(u8) {
/// /// Documentation for the first field.
/// FLAG1: 0;
/// /// Documentation for the second field.
/// FLAG2: 1;
/// MASK: 0, 1;
/// }
/// }
///
/// let mut b = ExampleBitfieldCustom::with_field_mask();
/// assert![b.is_field_mask()];
/// assert![b.is_field_flag1()];
/// assert![b.is_field_flag2()];
/// let _c = b.unset_field_flag1();
/// ```
pub struct ExampleBitfieldCustom(u8) {
/// Documentation for the first field.
FLAG1: 0;
/// Documentation for the second field.
FLAG2: 1;
#[allow(missing_docs)]
MASK0: 0, 1;
}
}
bitfield! {
/// An example created with [`bitfield!`], everything public.
///
/// ```
/// use devela::bitfield;
///
/// bitfield! {
/// /// An example created with [`bitfield!`], everything public.
/// pub struct ExampleBitfield(u8) {
/// /// Documentation for the first field.
/// FLAG1: 0;
/// /// Documentation for the second field.
/// FLAG2: 1;
/// MASK: 0, 1;
/// }
/// }
///
/// let mut b = ExampleBitfield::with_field_mask();
/// assert![b.is_field_mask()];
/// assert![b.is_field_flag1()];
/// assert![b.is_field_flag2()];
/// let _c = b.unset_field_flag1();
/// ```
pub struct ExampleBitfield(u8) {
/// Documentation for the first field.
FLAG1: 0;
/// Documentation for the second field.
FLAG2: 1;
#[allow(missing_docs)]
MASK0: 0, 1;
}
}
fn main() {}