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
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ErrorKind {
    NotConnected,
    AlreadyExists,
    Unsupported,
    Other,
}

#[derive(Debug)]
pub struct Error {
    kind: ErrorKind,
}

impl Error {
    pub fn new(kind: ErrorKind) -> Error {
        Error { kind }
    }

    pub fn kind(&self) -> ErrorKind {
        self.kind
    }
}

impl From<Error> for &'static str {
    fn from(error: Error) -> Self {
        match error.kind() {
            ErrorKind::NotConnected => "Communication error: NotConnected",
            ErrorKind::AlreadyExists => "Communication error: AlreadyExists",
            ErrorKind::Unsupported => "Communication error: Unsupported",
            ErrorKind::Other => "Communication error: Other",
        }
    }
}