bitx 0.2.0

More ergonomic way to deal with bitfield-like struct.
Documentation

bitx Version License Docs

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

at your option.