modular-bitfield
modular-bitfield copied to clipboard
Design: Make bitfields with `__` (double wildcard) identifier skip by default
Currently if you want to skip a bit field and are not interested in coming up with a name for it the best technique you can employ is:
#[bitfield]
struct HalfSkipped {
#[skip] __: B2,
value: B4,
#[skip] __: B2,
}
This issue proposes to automatically skip all fields with a name equal to __
(double wildcard) turning the above example into:
#[bitfield]
struct HalfSkipped {
__: B2,
value: B4,
__: B2,
}
Why double wildcard instead of a single one?
- A standard Rust parser does not accept a single wildcard (_
) as an identifier making it troublesome to use this in a proc. macro.
Unresolved: I am unsure about this design proposal since it is less transparent to a user than what we have right now. However, in case of many entirely skipped bit fields this is seriously cleaner syntactically.
I am interested in implementing this (have to deal with lots of skipped bits).
The bitfield-struct crate ignores fields that start with _
and has __
as an example in the docs so the concept already exists.
Rust tells you to add a _
prefix to function argument that are unused.
Unused struct fields don't need getters or setters so the logic is similar.
Rust allows _
as a variable name for stuff that needs to be assigned and is never used.
Again, the logic is similar.
Considering the use of underscore in rust, this seems to be in line. I would apply this logic to any struct field that starts with an underscore, like the bitfield-struct crate.
Design question: is skipping the default behavior (can be overridden with skip) or an enforced behavior (no overrides).