-
Notifications
You must be signed in to change notification settings - Fork 124
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
Derive TryFrom<T>
for enums marked #[repr(T)]
#146
Comments
I'm also interrested in this, and might look into implementation. I wonder what the best API would be here: Automatically just assume #[derive(TryFrom)]
#[repr(i16)]
enum Enum {} Have a #[derive(TryFromRepr)]
#[repr(i16)]
enum Enum {} Specify that it should derive #[derive(TryFrom)]
#[try_from(rerpr)]
#[repr(i16)]
enum Enum {} Also, there is a second part to this, deriving |
Thinking about it a bit more, I think the implicit behavior is fine, because Edit: nether mind, you can put repr on enums. so I'm not so sure anymore. |
So I implemented this now, for now it just automatically does the repl, not sure if that is something that should be controlled by an attribute, but I cannot think of any other usecases to derive right now. |
Keeping this open because of #300 (comment) |
C-like enums with an explicit
#[repr(<int type>)]
attribute can be cast to that integer type, but there's no easy way to convert back:This derive exists in
enum-utils
but it would be nice not to have to reach for multiple crates.The text was updated successfully, but these errors were encountered: