1use std::{error, result, fmt, io};
2
3#[derive(Debug, Clone)]
4pub enum ErrorKind {
5 InvalidMagicHeader,
6 InvalidCompressionMethod,
7 InvalidFlags,
8 InvalidCompressionFlags,
9 Io,
10 Other(String),
11}
12
13pub struct Error(pub ErrorKind, pub Option<Box<dyn error::Error + Send + Sync>>);
14
15impl From<io::Error> for Error {
16 fn from(err: io::Error) -> Self { Error(ErrorKind::Io, Some(Box::new(err))) }
17}
18
19impl error::Error for Error {
20 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
21 match &self.1 {
22 Some(err) => err.source(),
23 None => None,
24 }
25 }
26}
27
28impl fmt::Debug for Error {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match &self.1 {
31 Some(err) => err.fmt(f),
32 None => write!(f, "{:?}", self.0),
33 }
34 }
35}
36
37impl fmt::Display for Error {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 fmt::Debug::fmt(self, f)
40 }
41}
42
43pub type Result<T> = result::Result<T, Error>;