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
Specify the behavior of bitflags #369
Conversation
You make a recommendation for how to handle a bitflags type where you need to preserve all bits (define an I'd love to have native support for that (define a numeric field across a range of bits, get functions to get and set that value as a number), but in the absence of native support, I'd like to see a recommendation in the spec and documentation for how to handle those. I'm guessing the answer is "define a |
Also would you consider providing a version of the bitflags macro (with a different name) that doesn't require defining an
Another possibility would be a wrapper, something like |
I think this is a good use-case for bitfield libraries like
Ah that's a good alternative to consider. With the |
Giving this some more thought, I think a solution for unknown bits that applies at the definition would be best, because otherwise you have to audit all the places you use them. I think based on this spec, we could consider defining an alternative macro that simply forwarded to the regular one, but included the I’ve been trying to avoid having to duplicate the logic of the |
Valid. It'd be nice to have minimal support, but "use another library for that" is a fair response.
I think if the
Fair enough; that does sound appealing. Proposal: what if bitflags accepted |
Ah yes, I think this would be reasonable to do. The
I like this 👍 It has the benefit of being unsurprising syntactically and easy to detect in a |
There is a version of this spec we could ship without needing to make a major version bump:
That could let us defer any breaking version either indefinitely or at least for some time. |
I've updated this spec so it no longer requires any breaking changes; there will be no |
Read the draft here
First, I'd like to extend a huge and humble thank you to all
bitflags
users. We've had a few tricky releases this year and the results of a few bugs along the way will have sent some of you on long and arduous debugging journeys. I appreciate all the feedback and understanding you've provided along the way.A specification for
bitflags
After a lot of back-and-forth with users (such as in #363) I think I've settled on what is fundamentally not right with
bitflags
today; it has no solid foundation to build off. It started as a bit of a scrappy but handy macro for reducing a lot of boilerplate and has evolved into something rather more complex. Without any solid foundation much of that evolution has been ad-hoc and resulted in inconsistencies in behavior. That makes it difficult to predict and communicate whatbitflags
does and why in many cases.This PR aims to address that by introducing something of a formal specification for
bitflags
. It defines thebitflags
"domain" and fully specifies the behavior of the code it generates in a way that is consistent and predictable.What it means for you
This specification doesn't make any breaking changes to
bitflags
. It'll continue to work as it currently does, but its behavior is now made more obvious.At some point in the future (there's no hurry on this) we may do a
3.0.0
that makes operators like|
,&
, and^
truncate like!
does, but if you usebitflags_external
you won't need to make any changes to your code when that happens.