1
use serde::{Deserialize, Serialize};
2

            
3
16
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
4
struct SomeCollection {
5
    inner: Vec<SomeItem>,
6
}
7

            
8
8
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
9
struct SomeItem {
10
    #[serde(flatten)]
11
    foo: Foo,
12
    #[serde(flatten)]
13
    bar: Bar,
14
}
15

            
16
24
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
17
struct Bar {
18
    name: String,
19
    some_enum: Option<SomeEnum>,
20
}
21

            
22
16
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
23
struct Foo {
24
    something: String,
25
}
26

            
27
16
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
28
enum SomeEnum {
29
    A,
30
    B,
31
}
32

            
33
#[test]
34
4
fn roundtrip() {
35
4
    let scene = SomeCollection {
36
4
        inner: vec![SomeItem {
37
4
            foo: Foo {
38
4
                something: "something".to_string(),
39
4
            },
40
4
            bar: Bar {
41
4
                name: "name".to_string(),
42
4
                some_enum: Some(SomeEnum::A),
43
4
            },
44
4
        }],
45
4
    };
46
4

            
47
4
    let ron = ron::ser::to_string(&scene).unwrap();
48
4
    let de: SomeCollection = ron::de::from_str(&ron).unwrap();
49
4
    assert_eq!(de, scene);
50

            
51
4
    let ron = ron::ser::to_string_pretty(&scene, Default::default()).unwrap();
52
4
    let _deser_scene: SomeCollection = ron::de::from_str(&ron).unwrap();
53
4
    assert_eq!(de, scene);
54
4
}