mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
1612ff7a83
user-defined tuple struct could be used to improve type safety. TEST=cargo test BUG=None Change-Id: I8ce10fc51b79c277ab23029513b707f3dd621af5 Reviewed-on: https://chromium-review.googlesource.com/1546432 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
25 lines
463 B
Rust
25 lines
463 B
Rust
extern crate bit_field;
|
|
|
|
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));
|
|
}
|