Expand description
§bitx

bitx provides a prodecural macro for defining structures
with precise bit-level and byte-level fields,
using more ergonomic syntax.
§At a glance
Note that Big-Endian / MSB-0 is used.
use bitx::bits;
bits! {
pub struct Header: 4.4 { // size in `byte.bit` notation (so 36-bit)
// 1-bit fields automatically return `bool`
0.0 pub is_active: u1,
// Custom bit-widths are supported
0.1 pub status: u3,
// The `.0` bit offset can be omitted.
1 pub payload: u16,
// Unaligned cross-byte field
3.4 checksum: u8,
}
}use bitx::bits;
bits! {
pub enum State: 0.2 { // 2-bit enum
0 Inactive,
1 Active,
2 Error,
_ Unknown, // Default fallback for unmapped bit patterns
}
}See docs.rs for more information.
§License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option.
Macros§
- bits
- Defines a structure with precise bit-level and byte-level fields.
Traits§
- Bits
- A trait representing bit-manipulatability of struct.