Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #[skip] attribute for the fields of the #[bitfield] macro #42

Closed
Robbepop opened this issue Oct 30, 2020 · 3 comments
Closed

Add #[skip] attribute for the fields of the #[bitfield] macro #42

Robbepop opened this issue Oct 30, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@Robbepop
Copy link
Owner

Using the proposed #[skip] attribute on bitfield fields it is possible to entirely skip code generation for the flagged field. Also this allows to have two optional parameters, getters and setters that skips generation of the field's getters or setters respectively. By default #[skip] skips both, #[skip(getters)] only skips generation of getters, #[skip(setters)] only skips generation of setters and #[skip(getters, setters)] is just equal to #[skip].

@henrikssn
Copy link

This would also be useful to skip compiler errors on unused fields.

Example:

#[bitfield]
pub struct MyBitfield {
  pub foo: B2,
  unused: B1,
  pub bar: B5,
}
warning: associated function is never used: `unused`
    |
338 |   unused: B1,
    |   ^^^^^^

@Robbepop
Copy link
Owner Author

Robbepop commented Oct 30, 2020

As a trick it should be noted that it will be possible to use __ (double wildcard) as identifier with #[skip]:

#[bitfield]
pub struct Sparse {
    a: bool,
    #[skip] __: B10,
    b: bool,
    #[skip] __: B10,
}

@Robbepop
Copy link
Owner Author

Implemented in #49. Closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants