summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ron/examples/transcode.rs
blob: 115ac469d1d4e71977f05f35a406e0f4d8daa56d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use ron::value::Value;
use serde::Serialize;

fn main() {
    let data = r#"
        Scene( // class name is optional
            materials: { // this is a map
                "metal": (
                    reflectivity: 1.0,
                ),
                "plastic": (
                    reflectivity: 0.5,
                ),
            },
            entities: [ // this is an array
                (
                    name: "hero",
                    material: "metal",
                ),
                (
                    name: "monster",
                    material: "plastic",
                ),
            ],
        )
        "#;

    let value: Value = data.parse().expect("Failed to deserialize");
    let mut ser = serde_json::Serializer::pretty(std::io::stdout());
    value.serialize(&mut ser).expect("Failed to serialize");
}