use config::{Config, ConfigError, Environment, File}; use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Settings { pub bind: String, } impl Settings { pub fn new() -> Result { let mut s = Config::new(); // Set defaults s.set_default("bind", "0.0.0.0")?; s.set_default("port", 8080)?; // Try loading from file (config.json/toml/etc) s.merge(File::with_name("config").required(false))?; // Add in settings from the environment (with a prefix of SOOS) s.merge(Environment::with_prefix("soos"))?; // Deserialize and freeze conf s.try_into() } }