-
Notifications
You must be signed in to change notification settings - Fork 5
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 a check for if a bitmask is "full" (different to "all") #9
Comments
Hey, yes I am aware of the gotcha with |
Thank you for the suggestion of |
Thanks for this great project! I've been using it for a project and it's come in very handy.
One gotcha I've discovered is that the
::all()
method represents the maximum size of allowable bits given the size of the mask, which sounds reasonable in principle but in practice it limits it's usefulness unless the mask created makes use of all bits.Consider the following struct:
The result of this is that
::all()
represents values that aren't used and could therefore be invalid, but also it produces a value which doesn't represent the sum of all masked values, which also means.is_all()
is only useful for checking if the value is::all()
, rather than "full".As far as I can see the only way to see if a bitmask is "full" is to
|
all variants together, which can get quite wordy (alternatively set up a const/method for this).So I propose either:
:all()
such that it returns the|
of all variants. This could be done automatically, would have nice ergonomics, but would be a breaking change.:all()
, either by manually specifying the value returned or maybe a flag to opt-into the behaviour of returning the|
of all variants..is_full()
, which makes the check. This would be different from:all()
, which would mean the gotcha remains, but it would be the "easiest" change to implement IMO.In addition to these, I think it could also be useful to add a
.trunc()
method which zeroes out any bits that aren't represented in enums, so that (given the example) callingFoo::from(255).trunc()
would result in0b1111
, rather than0b11111111
.The text was updated successfully, but these errors were encountered: