diff --git a/src/battery.rs b/src/battery.rs index 9beb05e..8fe75dd 100644 --- a/src/battery.rs +++ b/src/battery.rs @@ -74,7 +74,7 @@ pub fn set_battery_charge_thresholds(start_threshold: u8, stop_threshold: u8) -> // Validate thresholds using `BatteryChargeThresholds` let thresholds = BatteryChargeThresholds::new(start_threshold, stop_threshold).map_err(|e| match e { - crate::config::types::ConfigError::ValidationError(msg) => { + crate::config::types::ConfigError::Validation(msg) => { ControlError::InvalidValueError(msg) } _ => ControlError::InvalidValueError(format!("Invalid battery threshold values: {e}")), diff --git a/src/config/load.rs b/src/config/load.rs index 3ac5ca1..b374a32 100644 --- a/src/config/load.rs +++ b/src/config/load.rs @@ -26,7 +26,7 @@ pub fn load_config_from_path(specific_path: Option<&str>) -> Result) -> Result Result { - let contents = fs::read_to_string(path).map_err(ConfigError::IoError)?; + let contents = fs::read_to_string(path).map_err(ConfigError::Io)?; let toml_app_config = - toml::from_str::(&contents).map_err(ConfigError::TomlError)?; + toml::from_str::(&contents).map_err(ConfigError::Toml)?; // Handle inheritance of values from global to profile configs let mut charger_profile = toml_app_config.charger.clone(); diff --git a/src/config/types.rs b/src/config/types.rs index 03711c1..b2f6091 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -23,17 +23,17 @@ pub struct BatteryChargeThresholds { impl BatteryChargeThresholds { pub fn new(start: u8, stop: u8) -> Result { if stop == 0 { - return Err(ConfigError::ValidationError( + return Err(ConfigError::Validation( "Stop threshold must be greater than 0%".to_string(), )); } if start >= stop { - return Err(ConfigError::ValidationError(format!( + return Err(ConfigError::Validation(format!( "Start threshold ({start}) must be less than stop threshold ({stop})" ))); } if stop > 100 { - return Err(ConfigError::ValidationError(format!( + return Err(ConfigError::Validation(format!( "Stop threshold ({stop}) cannot exceed 100%" ))); } @@ -100,29 +100,29 @@ pub struct AppConfig { // Error type for config loading #[derive(Debug)] pub enum ConfigError { - IoError(std::io::Error), - TomlError(toml::de::Error), - ValidationError(String), + Io(std::io::Error), + Toml(toml::de::Error), + Validation(String), } impl From for ConfigError { fn from(err: std::io::Error) -> Self { - Self::IoError(err) + Self::Io(err) } } impl From for ConfigError { fn from(err: toml::de::Error) -> Self { - Self::TomlError(err) + Self::Toml(err) } } impl std::fmt::Display for ConfigError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::IoError(e) => write!(f, "I/O error: {e}"), - Self::TomlError(e) => write!(f, "TOML parsing error: {e}"), - Self::ValidationError(s) => write!(f, "Configuration validation error: {s}"), + Self::Io(e) => write!(f, "I/O error: {e}"), + Self::Toml(e) => write!(f, "TOML parsing error: {e}"), + Self::Validation(s) => write!(f, "Configuration validation error: {s}"), } } }