use std::{error, fmt, io};
#[derive(Debug)]
pub enum Error {
Unsupported,
Io(io::Error),
Other(Box<dyn error::Error + Send + Sync + 'static>),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::Unsupported => f.write_str("unsupported"),
Error::Io(e) => fmt::Display::fmt(e, f),
Error::Other(e) => fmt::Display::fmt(e, f),
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Other(e) => Some(&**e),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(e: io::Error) -> Self {
Error::Io(e)
}
}
impl From<&'static str> for Error {
fn from(e: &'static str) -> Self {
Error::Other(e.into())
}
}