47 lines
948 B
Rust
47 lines
948 B
Rust
|
|
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<u8>,
|
|
dac_url : Option<String>
|
|
}
|
|
|
|
|
|
pub fn load_config( path : &str )-> Result<Conf, Box<dyn std::error::Error>> {
|
|
|
|
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::<Conf>()?;
|
|
// .try_deserialize::<HashMap<String, String>>()?;
|
|
|
|
println!(
|
|
"{:?}",
|
|
conf
|
|
);
|
|
|
|
Ok(conf)
|
|
} |