lj_rust/src/conf.rs

41 lines
846 B
Rust
Raw Normal View History

use config::Config;
2023-06-04 15:33:28 +00:00
use serde::{Serialize,Deserialize};
2023-06-04 13:09:15 +00:00
use crate::errors::LJResult;
2023-06-04 15:33:28 +00:00
#[derive(Serialize, Deserialize, Debug)]
2023-06-03 16:11:55 +00:00
pub struct Conf {
2023-06-03 21:27:12 +00:00
pub laser_id: u8,
pub debug: bool,
pub redis_url: String,
2023-06-04 15:33:28 +00:00
pub dac: DacFamily
}
#[derive(Serialize, Deserialize, Debug)]
pub enum DacFamily {
#[serde(rename = "helios")]
Helios(HeliosConf),
#[serde(rename = "etherdream")]
Etherdream(EtherDreamConf),
}
#[derive(Serialize, Deserialize, Debug)]
pub struct HeliosConf {
pub id: u8
}
#[derive(Serialize, Deserialize, Debug)]
pub struct EtherDreamConf {
pub url: String
}
2023-06-04 10:08:44 +00:00
impl Conf {
2023-06-04 13:09:15 +00:00
pub fn new(path: &str) -> LJResult<Conf> {
2023-06-04 10:08:44 +00:00
let settings = Config::builder()
.add_source(config::File::with_name(path))
.build()?;
let conf : Conf = settings.try_deserialize()?;
Ok(conf)
}
2023-06-03 16:11:55 +00:00
}