-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
First off: thanks for this crate!
The syntax is clean and intuitive, and is a lot easier to use than the other bitfield crates i've seen on crates.io.
Right now, the generated bitfield can only be backed by various integer types, which has 3 pretty major limitations:
- It limits the size of the bitfield to at most
sizeof(u128) - It forces the addition of additional padding bytes into types that don't necessarily need them (e.g: a bitfield composed of 3xu8 fields)
- It enforces alignment on the type, making it difficult to naturally use as part of
repr(packed)fields (orrepr(C)fields + something like thezerocopycrate)
A clean solution to overcoming all 3 of these limitations would be to support backing the generated bitfield using a [u8; N] array.
Happy to brainstorm specifics of syntax / featureset, but I was thinking it could look something like:
#[bitfield] // no explicit backing type specified
struct Foo {
foo: u64,
bar: u64,
#[bits(2)]
extra: u8,
#[bits(6)]
_reserved: u8 // must include explicit "padding" bits
}
static_assert_eq!(std::mem::size_of::<Foo>(), 8 + 8 + 1);
// no `From`/`Into` for any specific backing integer, but instead have a From/Into `[u8; N]`Cheers!
smmalis37, SalHe, BKSalman, dnomd343, pablosichert and 3 more
Metadata
Metadata
Assignees
Labels
No labels