Skip to content
BitField Supports for Rust
Rust
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src
.gitignore
Cargo.toml
LICENSE
README.md

README.md

rust-bitfield

BitField Supports for Rust

Examples

#![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);
}
You can’t perform that action at this time.