1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::fmt;

#[derive(Debug)]
pub struct Error {
    compat: Compat,
}

impl Error {
    pub fn compat(self) -> Compat {
        self.compat
    }
}

impl fmt::Display for Error {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.compat.fmt(f)
    }
}

#[derive(Debug, failure::Fail)]
pub enum Compat {
    #[fail(display = "custom error: {}", _0)]
    Custom(failure::Error),
}

impl<E> From<E> for Error
where
    E: Into<failure::Error>,
{
    fn from(err: E) -> Self {
        Self {
            compat: Compat::Custom(err.into()),
        }
    }
}

pub type Result<T> = std::result::Result<T, Error>;