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

ron serialization is incorrect when using Value as input #132

Open
wiiznokes opened this issue Nov 5, 2024 · 0 comments
Open

ron serialization is incorrect when using Value as input #132

wiiznokes opened this issue Nov 5, 2024 · 0 comments

Comments

@wiiznokes
Copy link

I'm not sure if this is a bug or expected. Here is a reproducible example:

#[test]
fn minimal_example() {
   
    #[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
    struct A {
        x: i32,
    }

    let value_before = A::default();
    let res = ron::ser::to_string_pretty(&Value::serialize(&value_before).unwrap(), ron::ser::PrettyConfig::default()).unwrap();
    let value_after: A = ron::from_str(&res).unwrap();

    assert_eq!(value_before, value_after);
}

The line let value_after: A = ron::from_str(&res).unwrap(); will trigger the panic.

Here is another example:

#[test]
fn minimal_example2() {

    #[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
    enum B {
        #[default]
        A,
        B,
        C
    }
   
    #[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq)]
    struct A {
        x: i32,
        s: String,
        e: B,
    }

    let value = A::default();

    let res1 = ron::ser::to_string_pretty(&value, ron::ser::PrettyConfig::default()).unwrap();
    let res2 = ron::ser::to_string_pretty(&Value::serialize(&value).unwrap(), ron::ser::PrettyConfig::default()).unwrap();

    println!("{res1}");
    println!("{res2}");

}
---- stdout ----
(
    x: 0,
    s: "",
    e: A,
)
{
    "e": "A",
    "s": "",
    "x": 0,
}
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

No branches or pull requests

1 participant