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
Implement serialization of tuple variants of flatten enums #2448
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mingun
force-pushed
the
ser-flatten-enums
branch
2 times, most recently
from
June 8, 2023 16:10
2fbce60
to
1986e92
Compare
(review with "ignore whitespace" option on and editor that shows line moves, for example, TortoiseGitMerge)
…) and names for tag and content fields
failures (1): flatten::enum_::externally_tagged::tuple
…ged enums The Container struct struct Container { #[serde(flatten)] enum_field: Enum, } enum Enum { Tuple(u32, u32), } now can be serialized to JSON as { "enum_field": [1, 2] } Deserialization already works Fixes (1): flatten::enum_::externally_tagged::tuple
…ten::enum_::externally_tagged::newtype
…for enums Those deserializers are used to deserialize tuple or struct variants from Content which is used by internally tagged enums and by flatten FlatMapDeserializer is reached in the following tests: flatten::enum_::externally_tagged::newtype flatten::enum_::externally_tagged::struct_from_map flatten::enum_::externally_tagged::struct_from_seq flatten::enum_::externally_tagged::tuple ContentDeserializer is reached in the following tests: test_enum_in_internally_tagged_enum test_internally_tagged_struct_variant_containing_unit_variant
Mingun
force-pushed
the
ser-flatten-enums
branch
from
July 11, 2023 17:02
1986e92
to
4e5e55b
Compare
dtolnay
approved these changes
Jul 30, 2023
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.
Thanks!
I appreciate the detour into improving the tests.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Actually, I investigating a way of possible fixes of #1183, during which I try to narrow frontier of work as much as possible. I investigating an idea of using configurable buffer instead of generic
Content
. During that I found that generalizing of this type requires some knowledge of theContent
internals --VariantDeserializer::tuple_variant
andVariantDeserializer::struct_variant
does the matching overContent
s content:serde/serde/src/private/de.rs
Lines 1553 to 1557 in 25381be
serde/serde/src/private/de.rs
Lines 1576 to 1583 in 25381be
Here I noticed, that
MapDeserializer
andSeqDeserializer
are different structs from the commonde::value
module. At first glance the difference is cosmetic, so I tried to remove custom implementations and use counterparts fromde::value
. The last commit of this PR does that and actually that was the commit that I want to PR.Because this change could have non-obvious consequences, I tried to find tests that reaches changed code paths. During that I found that for some of them there are no tests, so I write them.
However, in the process of writing tests, it turned out that deserialization of the enum tuple variant from sequence is supported, but such an enumeration cannot be serialized. So in the end I implemented that and close the gap.
When writing tests, I tried to organize them hierarchically, because in the current approach it is completely incomprehensible which parts are tested and which are not. Tests piled into a heap without any system. I found, that organizing tests using built-in capabilities of Rust -- modules -- greatly improves readability of tests and understanding of what is tested. Because tests in this PR not the main thing on which I focus, you can find that organizing of them are slightly incomplete. That is true. I plan to clean them up in the following PRs.