You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use std::{convert::Infallible, fmt};
|
|
|
|
#[derive(Debug)]
|
|
pub enum Ærror {
|
|
IOError(String),
|
|
ParseError(String),
|
|
ApplicationError(String),
|
|
}
|
|
|
|
impl Ærror {
|
|
pub fn new(message: String) -> Ærror {
|
|
Ærror::ApplicationError(message)
|
|
}
|
|
|
|
pub fn new_str(message: &str) -> Ærror {
|
|
Ærror::ApplicationError(String::from(message))
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for Ærror {}
|
|
|
|
impl fmt::Display for Ærror {
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
match self {
|
|
Ærror::IOError(message) => formatter.write_fmt(format_args!("IO Error: {}", message)),
|
|
Ærror::ParseError(message) => {
|
|
formatter.write_fmt(format_args!("Parse Error: {}", message))
|
|
}
|
|
Ærror::ApplicationError(message) => {
|
|
formatter.write_fmt(format_args!("Generic Error: {}", message))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for Ærror {
|
|
fn from(error: std::io::Error) -> Self {
|
|
Ærror::IOError(error.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<serde_json::Error> for Ærror {
|
|
fn from(error: serde_json::Error) -> Self {
|
|
Ærror::ParseError(error.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<Infallible> for Ærror {
|
|
fn from(_error: Infallible) -> Self {
|
|
panic!("Infallible failed");
|
|
}
|
|
}
|