use cfg_rs::*; use std::{collections::HashMap, env::set_var}; type R = Result; #[allow(dead_code)] #[derive(Debug, FromConfig)] #[config(prefix = "suit")] struct ConfigSuit { #[config(name = "val")] int: IntSuit, arr: Vec, brr: Vec>, #[config(name = "val")] map: HashMap, #[config(name = "map")] bap: HashMap>, crr: Vec, err: R, #[config(default = "${random.u64}")] rand: u64, } #[allow(dead_code)] #[derive(Debug, FromConfig)] struct FloatSuit { v1: f32, v2: f64, } #[allow(dead_code)] #[derive(Debug, FromConfig)] struct IntSuit { v1: u8, v2: u16, v3: u32, } fn main() -> Result<(), ConfigError> { set_var("RUST_LOG", "trace"); env_logger::init(); // This example need feature full to enable toml/yaml/json source, and load them from app.toml/yaml/json. let config = Configuration::with_predefined_builder() .set_profile("dev") .init()?; let mut i = 0; for name in config.source_names() { i += 1; println!("{}: {}", i, name); } let hello = config.get_predefined::()?; println!("{:?}", hello); Ok(()) }