-
Notifications
You must be signed in to change notification settings - Fork 154
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
Const enum variants names #75
Const enum variants names #75
Conversation
Why deprecate the function if you made the access via the function const too? |
Because I see no reasons to use the function, when you can use associated constant. |
Thanks for the PR! Sorry I thought I responded to this last week, but it looks like I forgot to. Based on #74, I don't think we should deprecate the function because it will be extracted into a trait, and those can't be Let's definitely get the associated constant added though :) |
So I must undeprecate |
…`enum_variant_names_inner`
Thanks! Merging #74 created a conflict so here's the resolution you'll want in the enum variants file. quote! {
impl #impl_generics ::strum::VariantNames for #name #ty_generics #where_clause {
/// Return a slice containing the names of the variants of this enum
#[allow(dead_code)]
fn variants() -> &'static [&'static str] {
Self::VARIANTS
}
}
impl #impl_generics #name #ty_generics #where_clause {
/// Names of the variants of this enum
#[allow(dead_code)]
pub const VARIANTS: &'static [&'static str] = &[ #(#names),* ];
}
} |
@Peternator7 shouldn't I add |
@WaffleLapkin, that would be preferred, but if I remember correctly, const in traits isn't supported on stable yet :( |
@Peternator7 |
@Peternator7 I've added |
@Peternator7 ping |
Thanks for the ping; I agree. Let's go ahead and remove the variants function |
Looks great! Thanks for the feature :) |
Yay! Btw, don't forget that these changes are breaking now ;) |
I tried to write code like this:
But I've found that
variants
fn is notconst
.This pr changes the behaviour of
EnumVariantNames
in that way:pub const VARIANTS: &'static [&'static str] = ...
to enumvariants
fnconst
variants
fn with a message like"Use `Letter::VARIANTS` instead"