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
use std::error; use std::io; use std::fmt; #[derive(Debug)] pub enum ProbeError { IO(io::Error), UnexpectedContent(String), InvalidInput(String) } impl From<io::Error> for ProbeError { fn from(error: io::Error) -> ProbeError { ProbeError::IO(error) } } impl fmt::Display for ProbeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ProbeError::IO(ref err) => write!(f, "{}", err), ProbeError::UnexpectedContent(ref err) => write!(f, "{}", err), ProbeError::InvalidInput(ref err) => write!(f, "{}", err) } } } impl error::Error for ProbeError { fn description(&self) -> &str { match *self { ProbeError::IO(ref err) => err.description(), ProbeError::UnexpectedContent(ref err) => err, ProbeError::InvalidInput(ref err) => err } } fn cause(&self) -> Option<&error::Error> { match *self { ProbeError::IO(ref err) => Some(err), ProbeError::UnexpectedContent(_) => None, ProbeError::InvalidInput(_) => None } } }