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
Auto generate values when no values are specified #236
Comments
Thanks for the suggestion @qwerty01! This seems reasonable to me. We've got concerns around forwards compatibility where flags inserted in the middle of the enum will change the meaning of any flags that appear after it, but that's already true of |
Would it be trivial to also allow resetting the counter? bitflags! {
struct Flags: u32 {
const A;
// B not used currently
const C = 0b0100; // reset counter
const D;
}
} gets automatically expanded to bitflags! {
struct Flags: u32 {
const A = 0b0001;
// 0b0010 skipped
const C = 0b0100;
const D = 0b1000;
}
} |
@shjohnson-pi I think so long as our semantics for what gets inferred is just a left-shift of the previous flag that should work. If in your example you defined |
@KodrAus since 2.0 is out (for the last several months), I guess that means this was rejected for 2.0? |
@tech6hutch I think this is something we can add without breakage so it could be introduced at any time. |
Is this possible to do with the rules macro, or is a derive macro needed? There are probably some tricks to keep a counter within a rules macro, but that sounds like it could be more trouble then it is worth. |
@tgross35 This is not that difficult to implement counter in rule macros, but it can lead to unintuitive and hard to read unfolding code. In fact, more importantly, integrating this functionality into the |
Maybe that will become more straightforward sometime soon :) rust-lang/rust#122808 (yes yes, MSRV) |
I think we could probably also do this using constants, since we already build a constant array of flag values. Constants may be the best approach here since we'll naturally handle |
In some cases, the actual values of the bitfields may not matter to the user, so it would be nice to have another expansion such that:
gets automatically expanded to
The text was updated successfully, but these errors were encountered: