common/emgauwa-lib/src/utils.rs

23 lines
620 B
Rust
Raw Normal View History

2022-07-17 18:19:36 +00:00
pub fn vec_has_error<T, E>(target: &[Result<T, E>]) -> bool {
2022-07-19 22:38:09 +00:00
target.iter().any(|t| t.is_err())
2022-07-17 18:19:36 +00:00
}
pub fn load_settings<T>(config_name: &str, env_prefix: &str) -> T
where
for<'de> T: serde::Deserialize<'de>
{
let default_file = config::File::with_name(&format!("emgauwa-{}", config_name))
.required(false);
config::Config::builder()
.add_source(default_file)
.add_source(
config::Environment::with_prefix(&format!("EMGAUWA_{}", env_prefix))
.prefix_separator("__")
.separator("__"),
)
.build()
.expect("Error building settings")
.try_deserialize::<T>()
.expect("Error reading settings")
}