use std::{error, result, fmt, io};
#[derive(Debug, Clone)]
pub enum ErrorKind {
InvalidMagicHeader,
InvalidCompressionMethod,
InvalidFlags,
InvalidCompressionFlags,
Io,
Other(String),
}
pub struct Error(pub ErrorKind, pub Option<Box<dyn error::Error + Send + Sync>>);
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self { Error(ErrorKind::Io, Some(Box::new(err))) }
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match &self.1 {
Some(err) => err.source(),
None => None,
}
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match &self.1 {
Some(err) => err.fmt(f),
None => write!(f, "{:?}", self.0),
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}
pub type Result<T> = result::Result<T, Error>;