summary refs log tree commit diff
path: root/bit_field/tests/test_tuple_struct.rs
blob: 13566a04b5af7751fe69af6e06a6299ef62bf4a2 (plain) (blame)
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
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use bit_field::*;

#[bitfield]
#[bits = 5]
#[derive(Debug, PartialEq)]
pub struct FiveBits(u8);

#[bitfield]
struct Struct {
    prefix: BitField1,
    five_bits: FiveBits,
    suffix: BitField2,
}

#[test]
fn test_enum() {
    let mut s = Struct::new();
    assert_eq!(s.get(0, 8), 0b_0000_0000);

    s.set_five_bits(FiveBits(0b10101));
    assert_eq!(s.get(0, 8), 0b_0010_1010);
    assert_eq!(s.get_five_bits(), FiveBits(0b10101));
}