use config::{File, Map}; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] #[serde(default)] pub struct Config { pub root: String, pub user: Vec, pub directories: Vec, pub custom_directories: Map } impl Default for Config { fn default() -> Self { Self { root: "/mnt/backup".to_string(), user: vec![], directories: vec![], custom_directories: Map::new(), } } } impl Config { pub fn load() -> Result { let config = config::Config::builder() .add_source(File::with_name("config.toml").required(false)) .add_source(config::Environment::with_prefix("FXBAUP").separator("_")) .build()?; config.try_deserialize() } }