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
use std::{convert::From, error, fmt, io};

/// Representation of an error.
#[derive(Debug)]
pub enum Error {
    // An error that can occur within libssh2.
    SSH2(ssh2::Error),
    // An io error.
    Io(io::Error),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            Error::Io(e) => e.fmt(f),
            Error::SSH2(e) => e.fmt(f),
        }
    }
}

impl error::Error for Error {}

impl From<ssh2::Error> for Error {
    fn from(e: ssh2::Error) -> Error {
        Error::SSH2(e)
    }
}

impl From<io::Error> for Error {
    fn from(e: io::Error) -> Error {
        Error::Io(e)
    }
}