Skip to content
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

Raw struct names cannot be deserialised #401

Closed
juntyr opened this issue Aug 20, 2022 · 0 comments · Fixed by #402
Closed

Raw struct names cannot be deserialised #401

juntyr opened this issue Aug 20, 2022 · 0 comments · Fixed by #402
Assignees

Comments

@juntyr
Copy link
Member

juntyr commented Aug 20, 2022

use ron::Error;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename = "Hello+World")]
struct RawStruct {
    #[serde(rename = "ab.cd-ef")]
    field: bool,
}

#[test]
fn test_raw_identifier_roundtrip() {
    let val = RawStruct { field: true };

    let ser =
        ron::ser::to_string_pretty(&val, ron::ser::PrettyConfig::default().struct_names(true))
            .unwrap();
    assert_eq!(ser, "r#Hello+World(\n    r#ab.cd-ef: true,\n)");

    // Fails with an error that "Hello+World" was expected but "Hello+World" was found
    let de: RawStruct = ron::from_str(&ser).unwrap();
    assert_eq!(de, val);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant