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
// This test is equivalent to 03-accessors but with some fields spanning across
// byte boundaries. This may or may not already work depending on how your
// implementation has been done so far.
//
//
// ║ first byte ║ second byte ║ third byte ║ fourth byte ║
// ╟───────────────╫───────────────╫───────────────╫───────────────╢
// ║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
// ╟─────────────────╫───────────╫─────────────────────────╫───────╢
// ║ a ║ b ║ c ║ d ║
use modular_bitfield_msb::prelude::*;
#[bitfield]
pub struct EdgeCaseBytes {
a: B9,
b: B6,
c: B13,
d: B4,
}
fn main() {
let mut bitfield = EdgeCaseBytes::new();
assert_eq!(0, bitfield.a());
assert_eq!(0, bitfield.b());
assert_eq!(0, bitfield.c());
assert_eq!(0, bitfield.d());
let a = 0b1100_0011_1;
let b = 0b101_010;
let c = 0x1675;
let d = 0b1110;
bitfield.set_a(a);
bitfield.set_b(b);
bitfield.set_c(c);
bitfield.set_d(d);
assert_eq!(a, bitfield.a());
assert_eq!(b, bitfield.b());
assert_eq!(c, bitfield.c());
assert_eq!(d, bitfield.d());
}