use std::error;
use std::fmt;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug)]
pub enum Error {
Custom(String),
IO(std::io::Error),
Fmt(std::fmt::Error),
FromUtf8Error(std::string::FromUtf8Error),
Utf8Err(std::str::Utf8Error),
}
impl<'a> fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Custom(s) => write!(f, "{}", s),
Self::IO(e) => write!(f, "{}", e),
Self::Fmt(e) => write!(f, "{}", e),
Self::Utf8Err(e) => write!(f, "{}", e),
Self::FromUtf8Error(e) => write!(f, "{}", e),
}
}
}
impl<'a> From<Error> for std::fmt::Error {
fn from(_: Error) -> Self {
std::fmt::Error
}
}
impl<'a> From<std::str::Utf8Error> for Error {
fn from(e: std::str::Utf8Error) -> Self {
Self::Utf8Err(e)
}
}
impl<'a> From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::IO(e)
}
}
impl<'a> From<std::string::FromUtf8Error> for Error {
fn from(e: std::string::FromUtf8Error) -> Self {
Self::FromUtf8Error(e)
}
}
impl<'a> error::Error for Error {}