diff --git a/src/config.rs b/src/config.rs index 19225c8..28e56d5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,13 +1,13 @@ use crate::Config; use dirs::config_dir; -use tracing::debug; use std::{ - fmt::{self, Display}, env, + fmt::{self, Display}, fs, io::ErrorKind, - path::PathBuf + path::PathBuf, }; +use tracing::debug; /// The name of the folder which holds the config pub const CONFIG_FOLDER_NAME: &'static str = "virtual-deck"; @@ -18,7 +18,7 @@ pub fn load_config() -> Result { Some(path) => { debug!("Using env variable: {:?}", path); PathBuf::from(path) - }, + } None => { // try to get the system config dir; env var required if not available if let Some(mut path) = config_dir() { @@ -27,7 +27,7 @@ pub fn load_config() -> Result { debug!("Using system path: {:?}", path); path } else { - return Err(ConfigError::PathNotAvailable()) + return Err(ConfigError::PathNotAvailable()); } } }; @@ -35,12 +35,14 @@ pub fn load_config() -> Result { let path = config_file.display().to_string().clone(); match fs::read_to_string(config_file) { - Ok(content) => toml::from_str(&content).map_err(|e| ConfigError::SyntaxError(e.to_string())), + Ok(content) => { + toml::from_str(&content).map_err(|e| ConfigError::SyntaxError(e.to_string())) + } Err(file_error) => { if file_error.kind() == ErrorKind::NotFound { - return Err(ConfigError::FilePathDoesNotExist(path)) + return Err(ConfigError::FilePathDoesNotExist(path)); } else { - return Err(ConfigError::ReadError(file_error.to_string())) + return Err(ConfigError::ReadError(file_error.to_string())); } } } @@ -53,10 +55,9 @@ pub enum ConfigError { PathNotAvailable(), SyntaxError(String), FilePathDoesNotExist(String), - ReadError(String) + ReadError(String), } - impl Display for ConfigError { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { match self { @@ -90,4 +91,3 @@ impl Display for ConfigError { } } } - diff --git a/src/device.rs b/src/device.rs index a69aad7..f8ab534 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,6 +1,6 @@ use crate::{ - modules::{retrieve_module_from_name, start_module, HostEvent}, config::ConfigError, + modules::{retrieve_module_from_name, start_module, HostEvent}, skip_if_none, unwrap_or_error, Button, DeviceConfig, }; use deck_driver as streamdeck; diff --git a/src/main.rs b/src/main.rs index 5a02090..7fd86fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,7 @@ use deck_driver as streamdeck; use device::Device; use hidapi::HidApi; use serde::Deserialize; -use std::{ - collections::HashMap, - sync::Arc, - time::Duration, process::exit, -}; +use std::{collections::HashMap, process::exit, sync::Arc, time::Duration}; use tracing::{debug, error, info, warn}; use tracing_subscriber::{ self, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, @@ -14,10 +10,9 @@ use tracing_subscriber::{ use config::load_config; +mod config; mod device; mod modules; -mod config; - #[macro_export] macro_rules! skip_if_none { @@ -156,7 +151,6 @@ pub async fn start_device( } } - #[derive(Deserialize, Debug, Clone)] pub struct DeviceConfig { pub serial: String,