File: transcode.rs

package info (click to toggle)
rust-ron 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: makefile: 2
file content (31 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (32)
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");
}