1
0
Fork 0
firefox/third_party/rust/ron/examples/decode_file.rs
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

37 lines
771 B
Rust

#![allow(dead_code)]
use std::{collections::HashMap, fs::File};
use ron::de::from_reader;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Config {
boolean: bool,
float: f32,
map: HashMap<u8, char>,
nested: Nested,
tuple: (u32, u32),
vec: Vec<Nested>,
}
#[derive(Debug, Deserialize)]
struct Nested {
a: String,
b: char,
}
fn main() {
let input_path = format!("{}/examples/example.ron", env!("CARGO_MANIFEST_DIR"));
let f = File::open(input_path).expect("Failed opening file");
let config: Config = match from_reader(f) {
Ok(x) => x,
Err(e) => {
println!("Failed to load config: {}", e);
std::process::exit(1);
}
};
println!("Config: {:?}", &config);
}