1 // Copyright 2019 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use bit_field::*; 6 7 #[bitfield] 8 #[bits = 5] 9 #[derive(Debug, PartialEq)] 10 pub struct FiveBits(u8); 11 12 #[bitfield] 13 struct Struct { 14 prefix: BitField1, 15 five_bits: FiveBits, 16 suffix: BitField2, 17 } 18 19 #[test] test_enum()20fn test_enum() { 21 let mut s = Struct::new(); 22 assert_eq!(s.get(0, 8), 0b_0000_0000); 23 24 s.set_five_bits(FiveBits(0b10101)); 25 assert_eq!(s.get(0, 8), 0b_0010_1010); 26 assert_eq!(s.get_five_bits(), FiveBits(0b10101)); 27 } 28