diff --git a/src/conf.rs b/src/conf.rs index 2b449ec..ad1a1f3 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -16,11 +16,14 @@ pub struct Conf { pub dac_id: Option, pub dac_url: Option, } -pub fn load_config(path: &str) -> Result> { - let settings = Config::builder() - .add_source(config::File::with_name(path)) - .build()?; - - let conf : Conf = settings.try_deserialize()?; - Ok(conf) + +impl Conf { + pub fn new(path: &str) -> Result> { + let settings = Config::builder() + .add_source(config::File::with_name(path)) + .build()?; + + let conf : Conf = settings.try_deserialize()?; + Ok(conf) + } } diff --git a/src/main.rs b/src/main.rs index ec5c507..2bef1f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use helios_dac::{ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use redis_ctrl::{RedisCtrl,Order}; -use conf::{load_config,Conf}; +use conf::Conf; use errors::LJError; const CENTER : (u16,u16) = (2000, 2000); @@ -36,7 +36,7 @@ fn run_all() -> Result<(), Box> { let Some(filename) = std::env::args().nth(1) else { return Err(Box::new(LJError::ConfigFileMissing)); }; - let config = load_config(&filename)?; + let config = Conf::new(&filename)?; let mut rs = RedisCtrl::new()?; let running = Arc::new(AtomicBool::new(true)); diff --git a/tests/test_conf.rs b/tests/test_conf.rs index a366a11..72dc44e 100644 --- a/tests/test_conf.rs +++ b/tests/test_conf.rs @@ -1,20 +1,20 @@ -use lj_rust::conf::{load_config, DacFamily}; +use lj_rust::conf::{Conf, DacFamily}; #[test] fn it_loads_a_valid_conf() { - let result = load_config("tests/settings/valid"); + let result = Conf::new("tests/settings/valid"); assert!(result.is_ok()); } #[test] fn it_fails_invalid_conf() { - let result = load_config("tests/settings/empty"); + let result = Conf::new("tests/settings/empty"); assert!(result.is_err()); } #[test] fn it_finds_struct_fields() { - let config = match load_config("tests/settings/valid") { + let config = match Conf::new("tests/settings/valid") { Ok(c) => c, Err(err) => { panic!("Unable to load config file: {:?}", err)