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
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum Error {
    LibError(std::ffi::c_int),
    Bug(&'static str),
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        match self {
            Self::LibError(e) => write!(f, "LibError({})", e),
            Self::Bug(e) => write!(f, "Bug({})", e),
        }
    }
}

impl From<i32> for Error {
    fn from(e: i32) -> Self {
        Self::LibError(e as std::ffi::c_int)
    }
}

impl From<u32> for Error {
    fn from(e: u32) -> Self {
        Self::LibError(e as std::ffi::c_int)
    }
}

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