-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Move EnumSet to std? #10272
Comments
It should be updated to implement |
I'm interested in taking this one on (assuming @nikomatsakis would not rather do it himself, of course) |
@martindemello be my guest. :) The main reason I did not move it to std in the first place was that I didn't want to invest a lot of energy in making it have a nice interface -- but also because we didn't have the deriving modes that would make it usable with |
okay, great :) i'll start figuring out a nice interface for it. |
The relevant traits are |
@sfackler Why |
They are more general than needed, but they can be automatically derived and |
oh, i see. yeah, that's a good point. it looks like FromPrimitive is derivable but ToPrimitive is not, though, and furthermore that FromPrimitive cannot be derived for structs (though that might be worth changing in the special case of a struct holding a single primitive field). i am unconvinced that there is a sufficient use case for this anyway, versus just calling to_uint when you hit the boundary with C code - at least, the way i am envisioning this being used is to maintain a set of flags in a typesafe way in rust code, and "emit" a uint when needed to pass to a C function. i guess the C function could theoretically want a mutable flagset that the caller is expected to preserve changes to, but i would still do that via an explicit to_uint and from_uint personally. is there some good case for this i'm missing? |
I personally have come to the conclusion that Here is a (slightly modified) excerpt from an e-mail that I wrote to @martindemello: I think we really need to decide what we are optimizing for. My
That is, a user who wants to declare an enum indicating a set of However, I do think that trying to make it nicer to work with C
Though it is not unheard of to do something like this as well:
The latter is convenient because you do not need to label
Note though that using explicit discriminants in place of indices
In my opinion the tradeoff is clear. Using indices makes EnumSet |
Agreed. I think the correct progression, then, is
|
That sounds correct. |
If EnumSet is being redesigned, #13756 is kinda related. My use case in Servo is unrelated to C. I just want a bunch of named bits, and I don’t care about the underlying enum (it only exists for EnumSet.) |
To make some progress on this issue (and the related #6085 which is blocked on it), I'm thinking of doing the following:
This would unblock #6085 by giving us C-compatible flag sets, without duplicating the |
Update on this issue: the bitflags! macro has been merged, as part of As per @nikomatsakis above, there is still a potential role for |
Any developments on this? What is the fate of EnumSet? |
EnumSet is no longer part of the public API. It is currently hosted in libcollections but not re-exported, so that the compiler can use it. It may reasonably be removed if the compiler stops using it. |
enhance [`ifs_same_cond`] to warn same immutable method calls as well fixes: rust-lang#10272 --- changelog: Enhancement: [`ifs_same_cond`]: Now also detects immutable method calls. [rust-lang#10350](rust-lang/rust-clippy#10350) <!-- changelog_checked -->
It's wanted for #6085, and generally OR-ing flags together is a common pattern for which we don't otherwise have a typesafe solution. Does EnumSet meet the high bar for inclusion in std? If so, then it's API probably needs careful consideration.
The text was updated successfully, but these errors were encountered: