From 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 11:12:04 +0200 Subject: do nearly anything to shut clippy up --- src/error.rs | 70 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index b4cc444..652fa0c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,16 +1,16 @@ use core::fmt; use serde::Deserialize; -pub type MLE = Result; +pub type MLE = Result; #[derive(Debug, Deserialize)] -pub struct MLError { - etype: ErrorType, +pub struct MLErr { + etype: EType, message: String, } #[derive(Debug, Deserialize)] -pub enum ErrorType { +pub enum EType { ArgumentError, ArgumentCountError, ConfigError, @@ -21,104 +21,106 @@ pub enum ErrorType { LibReq, LibChrono, LibJson, + LibIndicatif, IoError, Other, } -impl std::error::Error for MLError { +impl std::error::Error for MLErr { fn description(&self) -> &str { &self.message } } -impl fmt::Display for MLError { +impl fmt::Display for MLErr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.etype { - ErrorType::ArgumentError => { + EType::ArgumentError => { write!(f, "User input not accepted: {}", self.message) } - ErrorType::ArgumentCountError => { + EType::ArgumentCountError => { write!(f, "Too many/too few arguments") } - ErrorType::ConfigError => write!(f, "CONFIG"), - ErrorType::DBError => write!(f, "Database: {}", self.message), - ErrorType::ModError => write!(f, "Mod: {}", self.message), - ErrorType::LibToml => write!(f, "TOML"), - ErrorType::LibSql => write!(f, "SQL: {}", self.message), - ErrorType::LibReq => write!(f, "REQWEST"), - ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message), - ErrorType::LibJson => write!(f, "JSON: {}", self.message), - ErrorType::IoError => write!(f, "IO"), - ErrorType::Other => write!(f, "OTHER"), + EType::ConfigError => write!(f, "CONFIG"), + EType::DBError => write!(f, "Database: {}", self.message), + EType::ModError => write!(f, "Mod: {}", self.message), + EType::LibToml => write!(f, "TOML"), + EType::LibSql => write!(f, "SQL: {}", self.message), + EType::LibReq => write!(f, "REQWEST"), + EType::LibChrono => write!(f, "Chrono error: {}", self.message), + EType::LibJson => write!(f, "JSON: {}", self.message), + EType::LibIndicatif => write!(f, "Indicativ: {}", self.message), + EType::IoError => write!(f, "IO"), + EType::Other => write!(f, "OTHER"), } } } -impl From for MLError { +impl From for MLErr { fn from(error: reqwest::Error) -> Self { Self { - etype: ErrorType::LibReq, + etype: EType::LibReq, message: error.to_string(), } } } -impl From for MLError { +impl From for MLErr { fn from(error: toml::de::Error) -> Self { Self { - etype: ErrorType::LibToml, + etype: EType::LibToml, message: error.to_string(), } } } -impl From for MLError { +impl From for MLErr { fn from(error: rusqlite::Error) -> Self { Self { - etype: ErrorType::LibSql, + etype: EType::LibSql, message: error.to_string(), } } } -impl From for MLError { +impl From for MLErr { fn from(error: toml::ser::Error) -> Self { Self { - etype: ErrorType::LibToml, + etype: EType::LibToml, message: error.to_string(), } } } -impl From for MLError { +impl From for MLErr { fn from(error: chrono::ParseError) -> Self { Self { - etype: ErrorType::LibChrono, + etype: EType::LibChrono, message: error.to_string(), } } } -impl From for MLError { +impl From for MLErr { fn from(error: std::io::Error) -> Self { Self { - etype: ErrorType::IoError, + etype: EType::IoError, message: error.to_string(), } } } -impl From for MLError { +impl From for MLErr { fn from(value: serde_json::error::Error) -> Self { Self { - etype: ErrorType::LibJson, + etype: EType::LibJson, message: value.to_string(), } } } -impl MLError { - #[must_use] pub fn new(etype: ErrorType, message: &str) -> Self { +impl MLErr { + #[must_use] pub fn new(etype: EType, message: &str) -> Self { Self { etype, message: String::from(message), -- cgit v1.2.3