use std::{fmt, io};
#[derive(Debug)]
pub struct Error(ErrorKind);
#[derive(Debug)]
pub(crate) enum ErrorKind {
FromStr(String),
}
impl Error {
pub(crate) fn new(e: impl Into<ErrorKind>) -> Self {
Self(e.into())
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.0 {
ErrorKind::FromStr(e) => fmt::Display::fmt(e, f),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self.0 {
ErrorKind::FromStr(_) => None
}
}
}
impl From<Error> for io::Error {
fn from(e: Error) -> Self {
match e.0 {
ErrorKind::FromStr(e) => Self::new(io::ErrorKind::InvalidData, e),
}
}
}
impl From<String> for ErrorKind {
fn from(e: String) -> Self {
Self::FromStr(e)
}
}