#bitfields #utilities #macro

no-std bitutils

Bitfield macro and utilities

4 stable releases

Uses old Rust 2015

3.0.1 Apr 21, 2021
3.0.0 Oct 28, 2018
2.0.1 Sep 3, 2018
2.0.0 Sep 2, 2018

#1793 in Rust patterns

21 downloads per month

MIT license

7KB
100 lines

bitutils

API

At the core of bitutils lies one macro, bf!.

Syntax:

bf!(BitfieldName[uXX] {
    field1: lower:upper, // e.g. field1: 0:3, which would encompass the least significant nibble
    field2: 4:6,
    field3: 7:8,
    field5: 9:9,
    // ...
});

Usage:

let mut bf = BitfieldName::new(0xFFFF);
bf.field1();
bf.set_field2(0x3);
bf.val &= 0xFF;
println!("{:x?}", bf);

Bitutils also provides the bits! and bit! macros.

let foo = bits!(0xFFFF, 0:3);
assert_eq!(0xFF, foo);

let bar = bit!(0xF, 7);
assert_eq!(1, bar);

Dependencies

~2MB
~45K SLoC