Crates.io | mju-bits |
lib.rs | mju-bits |
version | 0.3.0 |
source | src |
created_at | 2020-01-02 01:39:41.694803 |
updated_at | 2020-01-03 19:28:34.1846 |
description | no_std typed bitfield access for u8, u16, u32 and u64 |
homepage | |
repository | https://github.com/davidkern/mju-bits |
max_upload_size | |
id | 194361 |
size | 29,635 |
#[no_std]
implementation of typed bitfield access for u8
, u16
, u32
, u64
and usize
.
use mju_bits::*;
struct RegisterMarker;
type Register = Storage<RegisterMarker, u32>;
type RegisterAll = BitField<Register, U0, U31>;
type RegisterFieldA = BitField<Register, U0, U7>;
type RegisterFieldB = BitField<Register, U8, U24>;
let mut reg = Register::new();
reg.set::<RegisterFieldA>(0x56);
reg.set::<RegisterFieldB>(0x1234);
assert_eq!(reg.get::<RegisterAll>(), 0x00123456);
The Storage type ensures that a field may only be used with its corresponding storage.
For example, this won't compile:
use mju_bits::*;
struct FooMarker;
type Foo = Storage<FooMarker, u8>;
type FooField = BitField<Foo, U0, U1>;
struct BarMarker;
type Bar = Storage<BarMarker, u8>;
let bar = Bar::new();
// Compiler error: FooField can not be used with Bar storage.
bar.get::<FooField>();
BitFields spanning multiple primitive types
Iterable sequences of BitFields, supporting functional protocol definition
Implementation compatible with generic consts on nightly
Improve types so larger bitfields can be supported - 128-bit fields break typenum
Others?
B0
..B63
aliases to avoid confusion with typenum::B0
and typenum::B1