-
Notifications
You must be signed in to change notification settings - Fork 151
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
support of default enum value #767
Conversation
0200a15
to
0e1cb38
Compare
cc @Emilgardis |
src/generate/register.rs
Outdated
impl From<#pc> for #fty { | ||
#[inline(always)] | ||
fn from(variant: #pc) -> Self { | ||
match variant { | ||
#casts | ||
} | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could also be a normal cast when the repr is fixed, or if this can't be fixed we should not use #[repr(u8)]
and provide a Into
impl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed repr
, but I don't see what is wrong with From
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I mentioned an Into in error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason repr couldn't be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Closes #172
This is usefull for (reading) fields like this:
![изображение](https://private-user-images.githubusercontent.com/3072754/284869132-209687ec-dbf2-44df-8bfc-b5e0ca931d4c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NDQ0NDksIm5iZiI6MTczODk0NDE0OSwicGF0aCI6Ii8zMDcyNzU0LzI4NDg2OTEzMi0yMDk2ODdlYy1kYmYyLTQ0ZGYtOGJmYy1iNWUwY2E5MzFkNGMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMTYwMjI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTVkMGU1MDA4MmQ3ZjAyOGM3OTZjODk0MmE3MjNlYmUzZWM4Y2UzOTMyMWMxOTcxYzc4Y2U2Mjc3OTdkOTZmYSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.GROiMRu9jGSznui1etf0n8s6m0BQ_9qifIhxpFnC0Ws)
For such fields changes look like:
![изображение](https://private-user-images.githubusercontent.com/3072754/284870336-3268a604-25f3-4ddf-bd54-d90bdf49cd72.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NDQ0NDksIm5iZiI6MTczODk0NDE0OSwicGF0aCI6Ii8zMDcyNzU0LzI4NDg3MDMzNi0zMjY4YTYwNC0yNWYzLTRkZGYtYmQ1NC1kOTBiZGY0OWNkNzIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMTYwMjI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTMyN2RhN2Y0ZmYwNTRkNGQ4ZTI5Y2VlYmE3NDE3MmUzMDJiNzBiMjRlZDc4MjY3NjVlZGVlNjU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