use std::sync::LazyLock; pub struct Settings { /// Base directory for config and cache files. /// Controlled by `MDRS_CLIENT_CONFIG_DIRNAME` env var (default: `~/.mdrs-client`). pub config_dirname: std::path::PathBuf, /// Maximum number of concurrent MDRS API requests used by upload/download. /// Controlled by `MDRS_CLIENT_CONCURRENT` env var (default: 10). pub concurrent: usize, } impl Settings { fn load() -> Self { let config_dirname = std::env::var("MDRS_CLIENT_CONFIG_DIRNAME") .ok() .map(|s| { if s.starts_with("~/") { dirs::home_dir() .unwrap_or_else(|| std::path::PathBuf::from(".")) .join(&s[2..]) } else { std::path::PathBuf::from(&s) } }) .unwrap_or_else(|| { dirs::home_dir() .unwrap_or_else(|| std::path::PathBuf::from(".")) .join(".mdrs-client") }); let concurrent = std::env::var("MDRS_CLIENT_CONCURRENT") .ok() .and_then(|s| s.parse::().ok()) .unwrap_or(10); Settings { config_dirname, concurrent, } } } pub static SETTINGS: LazyLock = LazyLock::new(Settings::load);