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 does not properly round trip through Value #121

Closed
jrmuizel opened this issue Aug 4, 2018 · 6 comments
Closed

Ron does not properly round trip through Value #121

jrmuizel opened this issue Aug 4, 2018 · 6 comments
Labels

Comments

@jrmuizel
Copy link

jrmuizel commented Aug 4, 2018

#[macro_use]
extern crate serde;

extern crate ron;
use ron::de::*;
use ron::ser;
use ron::value::Value;

#[derive(Serialize)]
struct Scene(Option<(u32, u32)>);

#[derive(Serialize)]
struct Scene2 {
    foo: Option<(u32, u32)>,
}

fn main() {
    {
        let s = ser::to_string(&Scene2 { foo: Some((1, 1)) }).unwrap();
        println!("{}", s);
        let scene: Value = from_str(&s).unwrap();
        println!("{:?}", scene);
    }
    {
        let s = ser::to_string(&Scene( Some((1, 1)) )).unwrap();
        println!("{}", s);
        let scene: Value = from_str(&s).unwrap();
        println!("{:?}", scene);
    }
}

The first example gives:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parser(ExpectedIdentifier, Position { col: 12, line: 1 })', libcore/result.rs:945:5

The second gives:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parser(ExpectedMapColon, Position { col: 6, line: 1 })', libcore/result.rs:945:5
@jrmuizel
Copy link
Author

jrmuizel commented Aug 4, 2018

It looks even plain tuples don't work:

    {
        let s = ser::to_string(&(1, 1) ).unwrap();
        println!("{}", s);
        let scene: Value = from_str(&s).unwrap();
        println!("{:?}", scene);
    }

gives:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Parser(ExpectedIdentifier, Position { col: 2, line: 1 })', libcore/result.rs:945:5

@torkleyy
Copy link
Contributor

torkleyy commented Aug 4, 2018 via email

@jrmuizel
Copy link
Author

jrmuizel commented Aug 4, 2018

Yeah this is using 0.3.0. How is it supposed to work? deserialize_any doesn't call deserialize_tuple.

@kvark kvark added the bug label Aug 5, 2018
@torkleyy
Copy link
Contributor

torkleyy commented Aug 5, 2018

Huh, it seems there are a couple of things not implemented for values. I'm surprised this wasn't noticed earlier.

@torkleyy
Copy link
Contributor

torkleyy commented Aug 5, 2018

@jrmuizel Sorry for the inconvenience, I've opened a PR to fix this: #124.

bors bot added a commit that referenced this issue Aug 7, 2018
124: Handle tuple deserialization in deserialize_any properly r=torkleyy a=torkleyy

Fixes #121 

Needs some more tests before merging. I'm not happy about all the lookahead that this requires, but I don't see a better solution.

Co-authored-by: Thomas Schaller <torkleyy@gmail.com>
@torkleyy
Copy link
Contributor

torkleyy commented Aug 7, 2018

I've just merged it, please let me know if there's anything else that's not working properly.

@bors bors bot closed this as completed in #124 Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants