#bit-fields #bitfields #value #define #traits

bin+lib easy-bitfield

A simple and easy to use bitfield library for Rust

1 unstable release

0.1.0 Jun 10, 2024

#17 in #bitfield

MIT license

17KB
332 lines

easy-bitfield

Easy bitfield manipulation crate. For examples look at examples/sample.rs and documentation for the crate.


lib.rs:

easy-bitfield

An easy to use bitfield crate that allows you to define bitfield type with any storage and value types you could imagine (aka implement ToBitfield and FromBitfield traits).

Example

use easy_bitfield::*;

pub type X = BitField<usize, bool, 0, 1, false>;
pub type Y = BitField<usize, u16, { X::NEXT_BIT }, 16, false>;
pub type Z = BitField<usize, i32, { Y::NEXT_BIT }, 32, true>;

let storage = AtomicBitfieldContainer::new(0);

storage.update::<X>(true);
storage.update::<Y>(42);
storage.update::<Z>(-42);

assert_eq!(-42, storage.read::<Z>());
assert_eq!(42, storage.read::<Y>());
assert!(storage.read::<X>());

Dependencies

~650KB
~12K SLoC