Crate easy_bitfield

Source
Expand description

§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>());

Structs§

AtomicBitfieldContainer
Atomic container for bitfield storage.
BitField
A bitfield descriptor type. Define an alias to this structure in order to use it properly.

Traits§

BitFieldTrait
Bitfield trait implementation, this is used to allow easy generic storage/value usage.
FromBitfield
ToBitfield