73 lines
1.5 KiB
Rust
73 lines
1.5 KiB
Rust
|
|
use std::error::Error;
|
||
|
|
use std::fmt;
|
||
|
|
use serenity::prelude::SerenityError;
|
||
|
|
|
||
|
|
pub type ManifoldResult<T> = Result<T, ManifoldError>;
|
||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
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<r2d2::Error> for ManifoldError {
|
||
|
|
fn from(err: r2d2::Error) -> Self {
|
||
|
|
ManifoldError::new(&err.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<std::io::Error> for ManifoldError {
|
||
|
|
fn from(err: std::io::Error) -> Self {
|
||
|
|
ManifoldError::new(&err.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<serde_json::error::Error> for ManifoldError {
|
||
|
|
fn from(err: serde_json::error::Error) -> Self {
|
||
|
|
ManifoldError::new(&err.to_string())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl From<regex::Error> 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<SerenityError> for ManifoldError {
|
||
|
|
fn from(err: SerenityError) -> Self {
|
||
|
|
ManifoldError::new(&err.to_string())
|
||
|
|
}
|
||
|
|
}
|