use std::error::Error; use std::fmt; use std::num::ParseIntError; use config::ConfigError; use serenity::prelude::SerenityError; use reqwest::Error as ReqwestError; pub type ManifoldResult = Result; #[derive(Debug, Serialize, Deserialize)] pub struct ManifoldError { pub details: String } impl ManifoldError { pub fn new(msg: &str) -> Self { Self { details: msg.to_string() } } } impl fmt::Display for ManifoldError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.details) } } impl Error for ManifoldError { fn description(&self) -> &str { &self.details } } impl From<()> for ManifoldError { fn from(_err: () ) -> Self { ManifoldError::new("Unspecified error") } } impl From for ManifoldError { fn from(err: r2d2::Error) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: std::io::Error) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: serde_json::error::Error) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: regex::Error) -> Self { ManifoldError::new(&err.to_string()) } } impl From<&str> for ManifoldError { fn from(err: &str) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: SerenityError) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: ReqwestError) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: ConfigError) -> Self { ManifoldError::new(&err.to_string()) } } impl From for ManifoldError { fn from(err: ParseIntError) -> Self { ManifoldError::new(&err.to_string()) } }