use std::{fmt, io};
#[derive(Debug)]
pub enum Error {
Encoding(String),
IO(io::Error),
Missing(String)
}
impl std::error::Error for Error {}
impl Error {
pub fn encoding(s: impl Into<String>) -> Self {
Self::Encoding(s.into())
}
pub fn missing(s: impl Into<String>) -> Self {
Self::Missing(s.into())
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::IO(err)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Encoding(s) => write!(f, "Not UTF-8: {s}"),
Self::IO(e) => write!(f, "I/O; {e}"),
Self::Missing(s) => write!(f, "Missing {s}")
}
}
}