refacto error handling
This commit is contained in:
parent
6bcfc831a6
commit
263ccf3210
@ -1,4 +1,4 @@
|
||||
laser_id = 1
|
||||
laser_id = 0
|
||||
debug = "true"
|
||||
redis_url = "127.0.0.1"
|
||||
dac_family = "Helios"
|
||||
|
21
src/conf.rs
21
src/conf.rs
@ -21,27 +21,12 @@ pub struct Conf{
|
||||
|
||||
|
||||
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 settings = Config::builder()
|
||||
.add_source(config::File::with_name(path))
|
||||
.build()?;
|
||||
|
||||
let conf = settings
|
||||
.try_deserialize::<Conf>()?;
|
||||
// .try_deserialize::<HashMap<String, String>>()?;
|
||||
|
||||
println!(
|
||||
"{:?}",
|
||||
conf
|
||||
);
|
||||
|
||||
Ok(conf)
|
||||
}
|
39
src/main.rs
39
src/main.rs
@ -16,15 +16,39 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use redis_ctrl::{RedisCtrl,Order};
|
||||
use conf::{load_config};
|
||||
use conf::{load_config,Conf};
|
||||
|
||||
|
||||
const CENTER : (u16,u16) = (2000, 2000);
|
||||
|
||||
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn main() {
|
||||
|
||||
let config = load_config("Settings")?;
|
||||
let config = match load_config("Settings") {
|
||||
Ok(c) => c,
|
||||
Err(err) => {
|
||||
panic!("Unable to load config file: {:?}", err)
|
||||
}
|
||||
};
|
||||
|
||||
let rs = match RedisCtrl::new() {
|
||||
Ok(rs) => rs,
|
||||
Err(err) => {
|
||||
panic!("Unable to connect to redis: {:?}", err);
|
||||
}
|
||||
};
|
||||
|
||||
match run_dac(config, rs) {
|
||||
Ok(()) => {},
|
||||
Err(err) => {
|
||||
panic!("Error: {:?}", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_dac(
|
||||
config: Conf,
|
||||
mut rs: RedisCtrl
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
|
||||
@ -32,15 +56,6 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
r.store(false, Ordering::SeqCst);
|
||||
}).expect("Error setting Ctrl-C handler");
|
||||
|
||||
let mut rs = match RedisCtrl::new() {
|
||||
Ok(rs) => rs,
|
||||
Err(err) => {
|
||||
println!("Unable to connect to redis: {:?}", err);
|
||||
return Ok(())
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let controller = NativeHeliosDacController::new()?;
|
||||
let devices = controller.list_devices()?;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user