Robbepop / modular-bitfield

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

Idea: Support wildcard as identifier for skipped fields in #[bitfield] #47

Closed Robbepop closed 3 years ago

Robbepop commented 3 years ago

To skip code generation for a field f we already planned to implement the #[skip] attribute. However, users still have to be creative to come up with some proper name for that field. What would be better, was if fields named _ (wildcard) would simply be treated as skipped fields.

Example

use modular_bitfield::prelude::*;

#[bitfield]
pub struct Sparse {
    a: bool,
    _: B10, // We skip the next 10 bits.
    b: bool,
    _: B10, // We skip the next 10 bits again.
}

Problem

The problem with this proposed solution is that in Rust _ is not parsed as identifier but as a keyword and therefore causes problems beyond what is easily (without hacks) achievable in a proc. macro today.

Robbepop commented 3 years ago

This is no longer really needed since with the most recent update it is now possible to have double wildcard + #[skip] have a similar effect as proposed here. Closed.