use std::{fmt, io};
#[derive(Debug)]
pub struct Error(ErrorKind);
#[derive(Debug)]
pub(crate) enum ErrorKind {
Yaml(serde_yaml::Error),
}
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::Yaml(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::Yaml(e) => Some(e),
}
}
}
impl From<Error> for io::Error {
fn from(e: Error) -> Self {
match e.0 {
ErrorKind::Yaml(e) => Self::new(io::ErrorKind::InvalidData, e),
}
}
}
impl From<serde_yaml::Error> for ErrorKind {
fn from(e: serde_yaml::Error) -> Self {
Self::Yaml(e)
}
}