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