Add minimal support for flattening roundtrips through maps#455
Merged
Conversation
This was referenced Apr 24, 2023
Closed
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #455 +/- ##
==========================================
- Coverage 87.06% 86.83% -0.24%
==========================================
Files 60 61 +1
Lines 7601 7967 +366
==========================================
+ Hits 6618 6918 +300
- Misses 983 1049 +66
☔ View full report in Codecov by Sentry. |
clouds56
reviewed
Apr 24, 2023
This was referenced May 21, 2023
juntyr
added a commit
to juntyr/ron
that referenced
this pull request
Aug 16, 2023
…n-rs#455) * Detect flattened structs in `Deserializer::deserialize_map` * Add minimal and targeted support for `#[serde(flatten)]` * Fix the serde flatten canary for MSRV 1.57 * Added extra tests for missing quotation marks in flattened struct field names * Clean up the serde flatten canary capture * Document the #[serde(flatten)] hack * Final small cleanup --------- Co-authored-by: Clouds Flowing <[email protected]>
This file contains hidden or 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
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.
Supersedes #403, #453, and #454 to add minimal support for
#[serde(flatten)]in RON. Instead of many workarounds to make flattened structs serialise into nice RON struct syntax and deserialise from them, both of which are really difficult since serde gives us no information to work with and just delegates to map serialisation/deserialisation, this PR just ensures that at least flattened structs can roundtrip through RON.For this, just one hack is necessary. If we detect that a map is deserialised into what looks like a struct (thanks @clouds56 for contributing the detection in #454), we enforce that map key identifiers are actually strings written exactly as
", identifier,". This seems to be enough to get the tests to work that I initially designed for #403.@torkleyy I'd be in favour of landing this instead of going down the rabbit hole of #403 since that just fixes one of the two parts and getting flattened structs to serialise correctly would require hacks of another order.
This would not really fix #115 but at least get some working if imperfect solution.
CHANGELOG.md