lj_rust/src/conf.rs

29 lines
569 B
Rust
Raw Normal View History

use config::Config;
use serde::Deserialize;
2023-06-03 16:54:41 +00:00
#[derive(Deserialize, Debug)]
pub enum DacFamily {
Helios,
2023-06-03 16:54:41 +00:00
Etherdream,
}
2023-06-03 16:54:41 +00:00
#[derive(Deserialize, Debug)]
2023-06-03 16:11:55 +00:00
pub struct Conf {
2023-06-03 16:54:41 +00:00
laser_id: u8,
debug: bool,
redis_url: String,
dac_family: DacFamily,
2023-06-03 16:54:41 +00:00
dac_id: Option<u8>,
dac_url: Option<String>,
}
2023-06-03 16:54:41 +00:00
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))
2023-06-03 16:54:41 +00:00
.build()?;
let conf = settings.try_deserialize::<Conf>()?;
Ok(conf)
2023-06-03 16:11:55 +00:00
}