ron-rs / ron

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

Fixes #511: Allow deserialize_string for map fields originating from struct-formatted maps #512

Closed grindvoll closed 9 months ago

grindvoll commented 9 months ago

This commit fixes an incoherence problem in the Deserializer implementation for fields in struct-encoded maps. deserialize_str was accepted, while deserialize_string was rejected. This behavior caused a problem when deserializing e.g. serde_json::Values from RON-files.

codecov-commenter commented 9 months ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (1ff0efa) 100.00% compared to head (3dc831f) 100.00%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #512 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 79 80 +1 Lines 11109 11178 +69 ========================================= + Hits 11109 11178 +69 ``` | [Files](https://app.codecov.io/gh/ron-rs/ron/pull/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [src/de/id.rs](https://app.codecov.io/gh/ron-rs/ron/pull/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL2RlL2lkLnJz) | `100.00% <100.00%> (ø)` | | | [tests/511\_deserialize\_any\_map\_string\_key.rs](https://app.codecov.io/gh/ron-rs/ron/pull/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dGVzdHMvNTExX2Rlc2VyaWFsaXplX2FueV9tYXBfc3RyaW5nX2tleS5ycw==) | `100.00% <100.00%> (ø)` | | | [tests/non\_identifier\_identifier.rs](https://app.codecov.io/gh/ron-rs/ron/pull/512?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-dGVzdHMvbm9uX2lkZW50aWZpZXJfaWRlbnRpZmllci5ycw==) | `100.00% <ø> (ø)` | | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/ron-rs/ron/pull/512/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: Have feedback on the report? Share it here.

juntyr commented 9 months ago

@grindvoll Thanks for the PR! It looks good to me once codecov is 100% and with the small CHANGELOG tweak.

juntyr commented 9 months ago

@grindvoll Could you add a second test function to the new file, which just checks your motivating case, e.g.

#[test]
fn ron_struct_as_json_map() {
    let json: serde_json::Value = ron::from_str("(f1: 0, f2: 1)").unwrap();
    assert_eq!(
        json,
        serde_json::Value::Object(
            [
                (
                    String::from("f1"),
                    serde_json::Value::Number(serde_json::Number::from(0))
                ),
                (
                    String::from("f2"),
                    serde_json::Value::Number(serde_json::Number::from(1))
                ),
            ]
            .into_iter()
            .collect()
        )
    );
}