| 1 | #![allow(dead_code)] |
| 2 | |
| 3 | use std::collections::HashMap; |
| 4 | |
| 5 | use ron::de::from_str; |
| 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 | option: Option<String>, |
| 15 | tuple: (u32, u32), |
| 16 | } |
| 17 | |
| 18 | #[derive(Debug, Deserialize)] |
| 19 | struct Nested { |
| 20 | a: String, |
| 21 | b: char, |
| 22 | } |
| 23 | |
| 24 | const CONFIG: &str = " |
| 25 | /* |
| 26 | * RON now has multi-line (C-style) block comments! |
| 27 | * They can be freely nested: |
| 28 | * /* This is a nested comment */ |
| 29 | * If you just want a single-line comment, |
| 30 | * do it like here: |
| 31 | // Just put two slashes before the comment and the rest of the line |
| 32 | // can be used freely! |
| 33 | */ |
| 34 | |
| 35 | // Note that block comments can not be started in a line comment |
| 36 | // (Putting a /* here will have no effect) |
| 37 | |
| 38 | ( |
| 39 | boolean: true, |
| 40 | float: 8.2, |
| 41 | map: { |
| 42 | 1: '1', |
| 43 | 2: '4', |
| 44 | 3: '9', |
| 45 | 4: '1', |
| 46 | 5: '2', |
| 47 | 6: '3', |
| 48 | }, |
| 49 | nested: Nested( |
| 50 | a: \"Decode me!\", |
| 51 | b: 'z', |
| 52 | ), |
| 53 | option: Some(\t \"Weird formatting!\" \n\n ), |
| 54 | tuple: (3 /*(2 + 1)*/, 7 /*(2 * 5 - 3)*/), |
| 55 | )"; |
| 56 | |
| 57 | fn main() { |
| 58 | let config: Config = match from_str(CONFIG) { |
| 59 | Ok(x) => x, |
| 60 | Err(e) => { |
| 61 | println!("Failed to load config: {}", e); |
| 62 | |
| 63 | std::process::exit(1); |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | println!("Config: {:?}", &config); |
| 68 | } |