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
use bincode_next::BitPacked;
#[derive(BitPacked, Debug, PartialEq, Clone, Copy)]
struct Valid {
#[bincode(bits = 7)]
val: u8,
}
#[test]
fn test_valid_bit_width() {
let _ = Valid { val: 100 };
}
// The following code will fail to compile if uncommented
// #[test]
// fn test_invalid_bit_width() {
// let val = Invalid { val: 100 };
// let mut buf = [0u8; 10];
// let _ = bincode_next::encode_into_slice(val, &mut buf, bincode_next::config::standard());
// }
//
// #[derive(BitPacked)]
// struct Invalid {
// #[bincode(bits = 9)]
// val: u8,
// }
#[derive(BitPacked, Debug, PartialEq, Clone, Copy)]
enum ValidEnum {
A {
#[bincode(bits = 7)]
val: u8,
},
}
#[test]
fn test_valid_enum_bit_width() {
let val = ValidEnum::A { val: 100 };
let mut buf = [0u8; 10];
let _ = bincode_next::encode_into_slice(val, &mut buf, bincode_next::config::standard());
}