Robbepop / modular-bitfield

Macro to generate bitfields for structs that allow for modular use of enums.
Apache License 2.0
155 stars 40 forks source link

Add `bytes = N` parameter to the `#[bitfield]` macro #34

Closed Robbepop closed 3 years ago

Robbepop commented 3 years ago

For checking whether a #[bitfield] struct is generated to be exactly N bytes big we could add a bytes = N parameter to the #[bitfield] proc. macro. For example for N = 32 a bitfield struct with a bid width of 25 up to 32 bits is going to be valid.

Example

#[bitfield(bytes = 4)]
struct TtResp {
    mregion: u8,
    sregion: u8, 
    mrvalid: bool,
    srvalid: bool,
    r: bool,
    rw: bool,
    nsr: bool,
    nsrw: bool,
    s: bool,
    irvalid: bool,
    iregion: u8,
}