use config::Config; use serde::Deserialize; #[derive(Deserialize,Debug)] pub enum DacFamily { Helios, Etherdream } #[derive(Deserialize,Debug)] pub struct Conf{ laser_id : u8, debug : bool, redis_url : String, dac_family: DacFamily, dac_id : Option, dac_url : Option } pub fn load_config( path : &str )-> Result> { let conf_builder = Config::builder() .add_source(config::File::with_name(path)); let settings = match conf_builder.build() { Ok(conf) => conf, Err(err) => { println!("Invalid configuration file / missing file: {:?}", err); return Err(Box::new(err)) } }; let conf = settings .try_deserialize::()?; // .try_deserialize::>()?; println!( "{:?}", conf ); Ok(conf) }