Debian Codegraph @

third_party/rust/ron/examples/decode_file.rs

raw
1 #![allow(dead_code)]
2
3 use std::{collections::HashMap, fs::File};
4
5 use ron::de::from_reader;
6 use serde::Deserialize;
7
8 #[derive(Debug, Deserialize)]
9 struct Config {
10 boolean: bool,
11 float: f32,
12 map: HashMap<u8, char>,
13 nested: Nested,
14 tuple: (u32, u32),
15 vec: Vec<Nested>,
16 }
17
18 #[derive(Debug, Deserialize)]
19 struct Nested {
20 a: String,
21 b: char,
22 }
23
24 fn main() {
25 let input_path = format!("{}/examples/example.ron", env!("CARGO_MANIFEST_DIR"));
26 let f = File::open(input_path).expect("Failed opening file");
27 let config: Config = match from_reader(f) {
28 Ok(x) => x,
29 Err(e) => {
30 println!("Failed to load config: {}", e);
31
32 std::process::exit(1);
33 }
34 };
35
36 println!("Config: {:?}", &config);
37 }