Open hecatia-elegua opened 1 year ago
I am currently working around this not being implemented yet by converting a uN
to its underlying storage representation (u8
, u32
, etc.), using the trait implementation from bit_field
here: BitField, and then repacking the uN
.
The linked crate/trait was the most-readable-to-code-using-it API design I had found to date for integrating bitflags-like things into existing numeric types. I don't love its panic behaviour, but otherwise, I'd use it if it integrated with types provided by arbitrary-int
.
@dicta Thank you for the info!
I guess I'll think about it now: I'm inclined to expand sth like
//...
struct Foo {
field1: u3,
#[flags(status)]
field2: bool,
field3: bool,
field4: bool,
field5: u2,
field6: bool,
}
to all their field getters and setters plus
fn status() -> u3
fn set_status(u3)
and then const
s for these three fields (like in bitflags, so you can |
them together). We could use BitField
too, but I'm trying to avoid user code which looks like set_bit(1)
, since it won't tell you anything at first glance.
I'm open to bikeshedding and also to just being proven wrong.
Not entirely sure what a good design might look like here.