-
Notifications
You must be signed in to change notification settings - Fork 155
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
EnumIndex implementation #185
Conversation
I went ahead and updated some things.
|
I got a version working to handle custom |
So in trying to get the CI passing, I finally installed rust 1.32 locally so I could run the tests, only to realize that |
Hey Drew; this looks like a great start. Thanks for putting in all the effort. In #186, someone is adding the |
Think I fixed everything mentioned. I added |
This is looking really good. I've got 2 questions for you:
quote! {
impl #impl_generics #name #ty_generics #where_clause {
#vis #const_if_possible fn from_discriminant(idx: #index_type) -> Option<#name #ty_generics> {
match idx {
#(#arms),*
}
}
}
} |
The different name makes sense and seems clearer. I went ahead and made the change. That's a good idea, and definitely simpler. I didn't like the One thing I'm wondering is how I've exposed the constants. I renamed them so they make a bit more sense, but I'm still not sure I like exposing them. Especially since there is an |
I removed the constants from the interface. It seems cleaner to just have this macro only generate the |
This is looking really good! Looks like there's a merge conflict that needs to be resolved. I don't want to bikeshed on the name too much, but it is easier to change before anyone depends on it. What do you think of |
I noticed the overlap with My other thought was just to extend |
Combining them is certainly interesting. One obstacle is that More generally, I wonder if the the 2 macros serve different users:
I could certainly be wrong and feel free to disagree, but I think they are probably best as 2 different macros because they are interesting in different scenarios. So having said all that, I'm still in favor of |
Looking at more things, I agree with you. I came across this PR which is adding a The only other aspect then is that this macro would have the same name as the rust feature. I don't see that as a problem as you would explicitly import this macro on use which should shadow the rust macro |
Everything looks good! Thanks for all the work on this. I'll try and get a release out in the next week or so with this and #186 |
It was a pleasure working with you on this. Thanks from a happy user of the library. |
Glad it works well for you! :D Just release 0.23 on crates. https://crates.io/crates/strum |
@Peternator7 This is an initial pass at an implementation of an index function that is
const
. The following lists some of the outstanding items. In addition, I'm really not sure I captured all of the desired behavior in that macro implementation.index
andconst_index
)try_
variants of the functions so that the non-try
versions panic on unknown value similar toIndex
trait returns anOption
?repr
(ie if the enum isrepr(u8)
)