| Crates.io | bitutils |
| lib.rs | bitutils |
| version | 3.0.1 |
| created_at | 2018-09-02 20:22:22.063492+00 |
| updated_at | 2021-04-21 06:52:42.588897+00 |
| description | Bitfield macro and utilities |
| homepage | |
| repository | https://github.com/archshift/bitutils-rs |
| max_upload_size | |
| id | 82677 |
| size | 7,226 |
At the core of bitutils lies one macro, bf!.
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,
// ...
});
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);