-
Notifications
You must be signed in to change notification settings - Fork 17
Description
This is something that it seems like the inner guts of the proc macro could probably handle, but the syntax isn't quite there. Basically a way to determine what the descriminant bit(s) are directly while keeping access to the rest of the fields in an appropriate way.
This would make using bitfields as unions much simpler and ideally safer, as the enum discriminants could be matched against in a way that statically prevented the "inner" fields from being accessed in that way.
I don't know exactly how I'd want it annotated but I'm thinking of something like:
#[bitenum(u16)]
enum Foo {
// If the MSB is zero, read the rest as a single 15 bit integer
A(u15), // some way to denote the MSB specifically as 0,
// Otherwise, read the remaining bits in chunks
C { // some way to denote the MSB specifically as 1,
/* other types adding up to 15 bits */
}
}
Basically
This is not a pressing issue, as I know that you can have overlapping bit fields, but it could provide an ergonomic way to pattern match and would feel very "rusty".
The thing that might be neater to see (and could maybe accomplish the same goal) would be support for tuple struct syntax in general.
This would be harder since there are no named fields, but this is just a pie in the sky idea anyway.