ron-rs / ron

Rusty Object Notation
https://docs.rs/ron
Apache License 2.0
3.31k stars 122 forks source link

Add minimal support for flattening roundtrips through maps #455

Closed juntyr closed 1 year ago

juntyr commented 1 year ago

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 https://github.com/ron-rs/ron/pull/403.

@torkleyy I'd be in favour of landing this instead of going down the rabbit hole of https://github.com/ron-rs/ron/pull/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 https://github.com/ron-rs/ron/issues/115 but at least get some working if imperfect solution.

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 97.50% and project coverage change: -0.24 :warning:

Comparison is base (484fcab) 87.06% compared to head (bcbb027) 86.83%.

:exclamation: Current head bcbb027 differs from pull request most recent head 775c39d. Consider uploading reports for the commit 775c39d to get more accurate results

:mega: 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 ```diff @@ 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 ``` | [Impacted Files](https://codecov.io/gh/ron-rs/ron/pull/455?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [src/de/mod.rs](https://codecov.io/gh/ron-rs/ron/pull/455?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2RlL21vZC5ycw==) | `73.73% <80.48%> (-3.19%)` | :arrow_down: | | [src/de/id.rs](https://codecov.io/gh/ron-rs/ron/pull/455?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2RlL2lkLnJz) | `87.65% <100.00%> (-12.35%)` | :arrow_down: | | [tests/115\_minimal\_flattening.rs](https://codecov.io/gh/ron-rs/ron/pull/455?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dGVzdHMvMTE1X21pbmltYWxfZmxhdHRlbmluZy5ycw==) | `100.00% <100.00%> (ø)` | | ... and [3 files with indirect coverage changes](https://codecov.io/gh/ron-rs/ron/pull/455/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.