2023-06-03 15:52:29 +00:00
|
|
|
|
|
|
|
use config::Config;
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Deserialize,Debug)]
|
|
|
|
pub enum DacFamily {
|
|
|
|
Helios,
|
|
|
|
Etherdream
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize,Debug)]
|
2023-06-03 16:11:55 +00:00
|
|
|
pub struct Conf {
|
2023-06-03 15:52:29 +00:00
|
|
|
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>> {
|
2023-06-03 16:11:55 +00:00
|
|
|
let settings = Config::builder()
|
|
|
|
.add_source(config::File::with_name(path))
|
|
|
|
.build()?;
|
2023-06-03 15:52:29 +00:00
|
|
|
|
|
|
|
let conf = settings
|
|
|
|
.try_deserialize::<Conf>()?;
|
2023-06-03 16:11:55 +00:00
|
|
|
|
2023-06-03 15:52:29 +00:00
|
|
|
Ok(conf)
|
2023-06-03 16:11:55 +00:00
|
|
|
}
|