-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add Enumerable trait and deriving mode #14002
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
Conversation
Enumerable is for enumerating all possible values of an enum. The deriving mode works for all C-like enums.
Why does this return impl Enumerable for Shape {
fn values() -> &'static [Shape] {
static VALUES: &'static [Shape] = [Circle, Square, Triangle];
VALUES
}
} |
Slices aren't representable in derivings, it looks like. Take a look at libsyntax/ext/deriving/ty.rs:81 -- there's no variant for |
@kemurphy that's just because there's been no previous need for it; the existence/non-existence is just an implementation detail and can freely be changed. |
Also, I somewhat think that |
@huonw Hmm. I considered Iterator before and decided
Given that, I think |
Hm, that's true... could have an extension trait for
I don't think this is necessarily a good idea, e.g. |
What do you mean? The proposed As for floating-point, yes, ranging over floating-point numbers has some issues. But from a practical standpoint it's a lot nicer to support |
This is a major feature request for std. Can you write it up as an RFC to solicit feedback on the design? |
Closing as this should have an RFC due to the scope of the change. |
resurrection of rust-lang/rust-clippy#10984 fixes rust-lang/rust-clippy#10981 changelog: [`sliced_string_as_bytes`]: add new lint `sliced_string_as_bytes`
Enumerable is for enumerating all possible values of an enum.
The deriving mode works for all C-like enums.
Use like so: