1use std::convert;
13use std::fmt;
14use std::io;
15
16#[derive(Debug)]
17pub enum Error {
18 Io(io::Error),
20 Unexpected(String),
22}
23
24impl ::std::error::Error for Error {
25 fn description(&self) -> &str {
26 match *self {
27 Error::Io(ref e) => e.description(),
28 Error::Unexpected(_) => "something unexpected",
29 }
30 }
31
32 fn cause(&self) -> Option<&::std::error::Error> {
33 match *self {
34 Error::Io(ref e) => Some(e),
35 _ => None,
36 }
37 }
38}
39
40impl fmt::Display for Error {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 match *self {
43 Error::Io(ref e) => e.fmt(f),
44 Error::Unexpected(ref s) => write!(f, "Unexpected: {}", s),
45 }
46 }
47}
48
49
50impl convert::From<io::Error> for Error {
51 fn from(e: io::Error) -> Error {
52 Error::Io(e)
53 }
54}