1 个不稳定版本
0.1.1 | 2019年11月8日 |
---|---|
0.1.0 |
|
#2996 在 Rust 模式
19KB
318 行
rust-bitfield
位字段对 Rust 的支持
示例
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
use bitfield::{bitfield_fields, BitRange, Bits};
// Define a BitField Type with 2 fields.
#[derive(Copy, Clone, Debug, Default)]
struct tV56aIEy_Bi1(u16);
impl tV56aIEy_Bi1 {
bitfield_fields! {
IEDZ, set_IEDZ : u16 [9..0];
_rb_, set__rb_ : u16 [15..10];
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Default)]
struct tV56aIEy {
IES0: u8,
IES1: u8,
IES2: u8,
IES3: u8,
bi1: tV56aIEy_Bi1,
}
fn main() {
let mut a = tV56aIEy::default();
assert_eq!(6, std::mem::size_of::<tV56aIEy>());
println!("{:?}", a);
println!("{:?}", a);
println!("IEDZ = {}, _rb_ = {}", a.bi1.IEDZ(), a.bi1._rb_());
println!("{:?}", a);
println!(
"IEDZ = {}, _rb_ = {}",
a.bi1.set_IEDZ(512).IEDZ(),
a.bi1._rb_()
);
println!("{:?}", a);
println!("IEDZ = {}, _rb_ = {}", a.bi1.IEDZ(), a.bi1._rb_());
println!("{:?}", a);
println!("IEDZ = {}, _rb_ = {}", a.bi1.IEDZ(), a.bi1._rb_());
println!("{:?}", a);
}