diff --git a/examples/simple_client.rs b/examples/simple_client.rs index 54880d2..c3ba977 100644 --- a/examples/simple_client.rs +++ b/examples/simple_client.rs @@ -17,5 +17,5 @@ fn do_something() -> redis::RedisResult<()> { } fn main() { - do_something(); + _ = do_something(); } diff --git a/src/conf.rs b/src/conf.rs index ad1a1f3..87e85c8 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,5 +1,6 @@ use config::Config; use serde::Deserialize; +use crate::errors::LJResult; #[derive(Deserialize, Debug)] pub enum DacFamily { @@ -18,7 +19,7 @@ pub struct Conf { } impl Conf { - pub fn new(path: &str) -> Result> { + pub fn new(path: &str) -> LJResult { let settings = Config::builder() .add_source(config::File::with_name(path)) .build()?; diff --git a/src/errors.rs b/src/errors.rs index 3c5446f..bb6900e 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -2,6 +2,8 @@ use std::error::Error; use std::fmt; use redis::RedisError; +pub type LJResult = Result>; + #[derive(Debug)] pub enum LJError { ConfigFileMissing, diff --git a/src/main.rs b/src/main.rs index d324b2d..a431c5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use redis_ctrl::{RedisCtrl,Order}; use conf::Conf; -use errors::LJError; +use errors::{LJError,LJResult}; const CENTER : (u16,u16) = (2000, 2000); @@ -32,7 +32,7 @@ pub fn main() { } } -fn run_all() -> Result<(), Box> { +fn run_all() -> LJResult<()> { let Some(filename) = std::env::args().nth(1) else { return Err(Box::new(LJError::ConfigFileMissing)); }; @@ -66,7 +66,7 @@ fn run_all() -> Result<(), Box> { Ok(()) } -fn get_helios_device() -> Result> { +fn get_helios_device() -> LJResult { let controller = NativeHeliosDacController::new()?; let devices = controller.list_devices()?; let Some(device) = devices.into_iter().next() else { @@ -81,7 +81,7 @@ fn get_next_frame( speed: u32, rs: &mut RedisCtrl, _black: bool -) -> Result> { +) -> LJResult { let line = rs.get(&format!("/pl/{}/0", config.laser_id))?; let line: Vec = line.iter().map(tuple_to_point).collect(); diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index e8971cc..7ae8d9f 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -1,6 +1,6 @@ use redis::{Client, Commands, Connection}; use ron::de::from_str; -use crate::errors::LJError; +use crate::errors::{LJError,LJResult}; #[repr(u8)] #[derive(Debug, PartialEq)] @@ -49,7 +49,7 @@ pub struct RedisCtrl { } impl RedisCtrl { - pub fn new(url: &str) -> Result> { + pub fn new(url: &str) -> LJResult { let client = Client::open(url) .map_err(LJError::RedisConnect)?; let connection = client.get_connection() @@ -57,13 +57,13 @@ impl RedisCtrl { Ok(RedisCtrl { client, connection }) } - pub fn get(&mut self, key: &str) -> Result> { + pub fn get(&mut self, key: &str) -> LJResult { let val: String = self.connection.get(key)?; let line: Line = from_str(&val)?; Ok(line) } - pub fn get_order(&mut self, id: u8) -> Result> { + pub fn get_order(&mut self, id: u8) -> LJResult { let path = format!("/order/{id}"); let val: u8 = self.connection.get(path.clone())?;