d/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3
4pub type Result<T> = ::std::result::Result<T, Error>;
5
6#[derive(Debug)]
7pub enum Error {
8    Io(String),
9}
10
11impl fmt::Display for Error {
12    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
13        match *self {
14            Error::Io(ref msg) => writeln!(f, "Io error: {}", msg),
15        }
16    }
17}
18
19impl StdError for Error {
20    fn description(&self) -> &str {
21        match *self {
22            Error::Io(ref msg) => msg,
23        }
24    }
25
26    fn cause(&self) -> Option<&StdError> {
27        match *self {
28            Error::Io(_) => None,
29        }
30    }
31}
32
33impl From<std::io::Error> for Error {
34    fn from(err: std::io::Error) -> Error {
35        Error::Io(err.description().to_string())
36    }
37}