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
45
46
47
48
49
50
51
52
use std::result;
use std::io::Error as IoError;
use std::convert::From;
use std::string::FromUtf8Error;
use core::num::ParseIntError;
use mmap::MapError;

use self::Error::{
    RootRequired,
    UnexpectedError,
    UnsupportedHardware,
    UnconnectedPin,
    Io,
    Map
};

#[derive(Debug)]
pub enum Error {
    RootRequired,
    UnexpectedError,
    UnsupportedHardware,
    UnconnectedPin,
    Map(MapError),
    Io(IoError),
}

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

impl From<IoError> for Error {
    fn from(err: IoError) -> Error {
        Io(err)
    }
}

impl From<MapError> for Error {
    fn from(err: MapError) -> Error {
        Map(err)
    }
}


impl From<ParseIntError> for Error {
    fn from(_: ParseIntError) -> Error {
        UnexpectedError
    }
}

impl From<FromUtf8Error> for Error {
    fn from(_: FromUtf8Error) -> Error {
        UnexpectedError
    }
}