Skip to content
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

Merged
merged 3 commits into from
Nov 23, 2023
Merged

support of default enum value #767

merged 3 commits into from
Nov 23, 2023

Conversation

burrbull
Copy link
Member

@burrbull burrbull commented Nov 21, 2023

Closes #172

This is usefull for (reading) fields like this:
изображение

For such fields changes look like:
изображение
изображение

@burrbull
Copy link
Member Author

cc @Emilgardis

src/generate/register.rs Outdated Show resolved Hide resolved
Comment on lines 1540 to 1548
impl From<#pc> for #fty {
#[inline(always)]
fn from(variant: #pc) -> Self {
match variant {
#casts
}
}
}
});
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I started I thought it is impossible, but after refactoring and when you've asked the question it looks simple.
Now changes much smaller:
изображение

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@burrbull burrbull added this pull request to the merge queue Nov 23, 2023
Merged via the queue into master with commit 2fd1d1f Nov 23, 2023
43 checks passed
@burrbull burrbull deleted the isdefault branch November 23, 2023 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When isDefault is present in an enumeratedValue, map all non-specified reads to that variant
2 participants