-
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
TryFrom<Repr> for enums using FromRepr? #328
Comments
I appreciate the sentiment; however, I am hesitant to make a change like this. I get a lot of issues asking for the same implementation of an existing macro, but with a different trait, or a different error type. They're all valid, but it makes configuration confusing, and it's difficult to pick one error type in particular that will make everyone happy. Here's a playground link that shows why it's hard. The error type being anything other than zero-sized changes the size of the returned If you're interested on working on this, I would accept a PR if the following were configurable.
Something like |
I see what you mean about sizes. I personally don't see caring about the size of a I would like to work on this, seems like the type of thing to get started with proc macros. Unfortunately, I do not have the capability to commit to working on it. In the interest of further discussion (in case I or someone else does end up writing a PR in the future), some questions:
Thinking on it further, while it does not align with the current API of |
I have quite a few places where
.try_into()?
is cleaner and more idiomatic than.from_repr().ok_or(/* insert error here */)?
.As such, I would love if there was a macro that implemented that TryInto. I put an example
TryFrom
at thend, it's a pretty generic thing, as most of the stuff is already done byFromRepr
.There's two open questions:
anyhow::Error
, and I would love for it to contain the failed value.Default
?The text was updated successfully, but these errors were encountered: