Skip to content

Allow only one unit variant in untagged enums #2937

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented May 31, 2025

We cannot distinguish between them when deserialize, so prohibit that to protect from possible errors.

If you really need several unit variants, mark all of them except one with #[serde(skip_deserializing)].

Several units still are allowed for serialization, because that will allow to add to the enums new preferred unit variant and deprecate the old without breaking changes. Both (new and old) would be serialized to the same value, but deserialization will get you only new variant.

…inguish between them when deserialize

If you really need several unit variants, mark all of them except one with `#[serde(skip_deserializing)]`
@Mingun Mingun force-pushed the only-one-unit-variant-in-untagged-enum branch from 8707d4d to cf668e3 Compare June 15, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant