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
UPDATED: Integer/boolean tags for internally/adjacently tagged enums #2525
base: master
Are you sure you want to change the base?
Conversation
Is there still any blocking point for this PR after update and pass CI? |
The new adjacently tagged enum code really put a wrench into this. It effectively now serializes tags into a unit enum like: enum EnumTag {
A,
B,
// ...
} This way some (de)serializers can use the variant index instead of the name for smaller sizes. However there is no (de)serialize method that takes a variant index and a generic data type. The closest is A new (de)serialize method could be created for this, something like A default impl would simply redirect to the newtype's serialize impl I think. |
@dtolnay is making a new base serialization method a good solution here? It could even expand enum tags to more than booleans and integers later on and add support for non-string tags for unit enums. |
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 would not accept a new Serializer method.
I have not gotten a chance to look over the code in the PR, but in response to the last 2 comments: I don't immediately see why recent adjacently tagged enum changes (referring to #2505/#2496) would be an obstacle. Enums that use all integer tags need to serialize the tag using the appropriately sized integer type's Serialize impl, and deserialize using that same integer type. Similarly enums that use all boolean tags need to serialize using serialize_bool and deserialize using deserialize_bool. Enums that use a mix of integer and boolean and string tags, if this is supported, need to deserialize using deserialize_any. It's not clear to me that the solution would have been any different prior to #2505.
It not necessarily an obstacle, but it does mean I need to do a slight rework of the (de)serialization of tags. Your implementation suggestion actually makes a lot of sense, I'll work on that one. |
bdd2f52
to
c53a298
Compare
Alright, that should be up-to-date again now |
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.
Thank you for getting this moving.
I have not looked at any deserialization code yet, but a few comments on the rest.
5 | / #[serde(rename = 1)] | ||
6 | | A, | ||
| |_____^ |
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.
It would be better to highlight the rename = 1
attribute for this error.
#[serde(rename = 1)]
^^^^^^^^^^
6 | / #[serde(rename = 1)] | ||
7 | | A, | ||
| |_____^ |
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.
Same here, please put the span on rename = 1
.
I've now done most of the simple changes. The rest of the requested changes will be completed on a later date |
@Astavie, that's an amazing piece of work, well done! May we help you somehow? |
@xamgore |
Support for marking specific integer types has been added. Specifically: Rules for unmarked integers:
|
this is basically just #2056 but synced with the latest serde master
closes #745
for implementation details see #2056
Example