New to Rust! Currently, I am playing around with toml-rs library to read TOML configuration.
See my code on Rust Playground
Here's code that I took from toml-rs' examples/decode.rs and updated the code
use serde::Deserialize;
use toml;
#[derive(Debug, Deserialize)]
struct Config {
active_users: Vec<String>,
// john: Option<User>, - i don't want to manually add each line for all tables
}
#[derive(Debug, Deserialize)]
struct User {
name: String,
}
fn main() {
let toml_str = r#"
active_users = ["john", "new2rust"]
[john]
name = "John Doe"
[new2rust]
name = "Jane Doe"
[randomguy]
name = "Rust Guy"
"#;
let decoded: Config = toml::from_str(toml_str).unwrap();
println!("{:#?}", decoded);
}
output
Config {
active_users: [
"john",
"new2rust",
],
}
My desired output would be like this
Config {
active_users: [
"john",
"new2rust",
],
john: ...,
new2rust: ...,
randomguy: ...,
}
I don't want to manually add each line john: Option<User> to Config for all other tables since configuration will be updated frequently. So I am not sure how to catch all tables and add them to Config with toml-rs.