From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- third_party/rust/ron/examples/decode.rs | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 third_party/rust/ron/examples/decode.rs (limited to 'third_party/rust/ron/examples/decode.rs') diff --git a/third_party/rust/ron/examples/decode.rs b/third_party/rust/ron/examples/decode.rs new file mode 100644 index 0000000000..56a9f30074 --- /dev/null +++ b/third_party/rust/ron/examples/decode.rs @@ -0,0 +1,67 @@ +#![allow(dead_code)] + +use ron::de::from_str; +use serde::Deserialize; +use std::collections::HashMap; + +#[derive(Debug, Deserialize)] +struct Config { + boolean: bool, + float: f32, + map: HashMap, + nested: Nested, + option: Option, + tuple: (u32, u32), +} + +#[derive(Debug, Deserialize)] +struct Nested { + a: String, + b: char, +} + +const CONFIG: &str = " +/* + * RON now has multi-line (C-style) block comments! + * They can be freely nested: + * /* This is a nested comment */ + * If you just want a single-line comment, + * do it like here: +// Just put two slashes before the comment and the rest of the line +// can be used freely! +*/ + +// Note that block comments can not be started in a line comment +// (Putting a /* here will have no effect) + +( + boolean: true, + float: 8.2, + map: { + 1: '1', + 2: '4', + 3: '9', + 4: '1', + 5: '2', + 6: '3', + }, + nested: Nested( + a: \"Decode me!\", + b: 'z', + ), + option: Some(\t \"Weird formatting!\" \n\n ), + tuple: (3 /*(2 + 1)*/, 7 /*(2 * 5 - 3)*/), +)"; + +fn main() { + let config: Config = match from_str(CONFIG) { + Ok(x) => x, + Err(e) => { + println!("Failed to load config: {}", e); + + std::process::exit(1); + } + }; + + println!("Config: {:?}", &config); +} -- cgit v1.2.3