-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add minimal support for flattening roundtrips through maps #455
Conversation
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. |
…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]>
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