From 414e83f696e5b25b58400ed8169ca38d99f1302f Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Sat, 26 Feb 2022 11:06:23 -0600 Subject: [PATCH] refactor: import cleanup for config --- src/config.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index 1f8c8b8..ba60c5b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ //! Configuration file and settings management +use config::{Config, ConfigError, File}; use lazy_static::lazy_static; use log::*; use serde::{Deserialize, Serialize}; @@ -138,27 +139,25 @@ pub struct Settings { impl Settings { pub fn new() -> Self { - let d = Self::default(); + let default_settings = Self::default(); // attempt to construct settings with file - // Self::new_from_default(&d).unwrap_or(d) - let from_file = Self::new_from_default(&d); + let from_file = Self::new_from_default(&default_settings); match from_file { Ok(f) => f, Err(e) => { warn!("Error reading config file ({:?})", e); - d + default_settings } } } - fn new_from_default(default: &Settings) -> Result { - // let config: config::Config = config::Config::new(); - let builder = config::Config::builder(); - let config: config::Config = builder + fn new_from_default(default: &Settings) -> Result { + let builder = Config::builder(); + let config: Config = builder // use defaults - .add_source(config::Config::try_from(default)?) + .add_source(Config::try_from(default)?) // override with file contents - .add_source(config::File::with_name("config")) + .add_source(File::with_name("config")) .build()? .try_into() .unwrap();