summaryrefslogtreecommitdiffstats
path: root/src/os/errors.rs
blob: bb3d6db94e29981c29e61fbf69189d93b8ce0964 (plain)
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
39
40
41
42
43
44
use std::fmt;

use failure::{Backtrace, Context, Fail};

#[derive(Debug)]
pub struct GetInterfaceError {
    inner: Context<GetInterfaceErrorKind>,
}

impl From<GetInterfaceErrorKind> for GetInterfaceError {
    fn from(kind: GetInterfaceErrorKind) -> GetInterfaceError {
        GetInterfaceError {
            inner: Context::new(kind),
        }
    }
}

impl From<Context<GetInterfaceErrorKind>> for GetInterfaceError {
    fn from(inner: Context<GetInterfaceErrorKind>) -> GetInterfaceError {
        GetInterfaceError { inner }
    }
}
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
pub enum GetInterfaceErrorKind {
    #[fail(display = "{}", _0)]
    PermissionError(String),
    #[fail(display = "{}", _0)]
    OtherError(String),
}
impl Fail for GetInterfaceError {
    fn cause(&self) -> Option<&dyn Fail> {
        self.inner.cause()
    }

    fn backtrace(&self) -> Option<&Backtrace> {
        self.inner.backtrace()
    }
}

impl fmt::Display for GetInterfaceError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        fmt::Display::fmt(&self.inner, f)
    }
}