email_format/rfc5322/
error.rs

1
2use std::error::Error as StdError;
3use std::fmt;
4use std::io::Error as IoError;
5
6pub enum ParseError {
7    Eof(&'static str),
8    NotFound(&'static str),
9    Expected(Vec<u8>),
10    ExpectedType(&'static str),
11    Io(IoError),
12    InvalidBodyChar(u8),
13    LineTooLong(usize),
14    TrailingInput(&'static str, usize),
15    InternalError,
16    Parse(&'static str, Box<ParseError>),
17}
18
19impl fmt::Display for ParseError {
20    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>
21    {
22        match *self {
23            ParseError::Eof(ref field) => write!(f, "End of File while looking for \"{}\"", field),
24            ParseError::NotFound(ref token) => write!(f, "\"{}\" Not Found", token),
25            ParseError::Expected(ref bytes) => write!(f, "Expectation Failed. Expected \"{:?}\"", bytes),
26            ParseError::ExpectedType(ref t) => write!(f, "Expectation Failed. Expected {}", t),
27            ParseError::Io(ref e) => write!(f, "I/O Error: {}", e),
28            ParseError::InvalidBodyChar(ref c) => write!(f, "Invalid Body Character: {} is not 7-bit ASCII", c),
29            ParseError::LineTooLong(ref l) => write!(f, "Line {} is too long", l),
30            ParseError::TrailingInput(ref field, ref c) => write!(f, "Trailing input at byte {} in {}", c, field),
31            ParseError::InternalError => write!(f, "Internal error"),
32            ParseError::Parse(ref field, ref inner) => write!(f, "Unable to parse {}: {}", field, inner),
33        }
34    }
35}
36
37impl fmt::Debug for ParseError {
38    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error>
39    {
40        <Self as fmt::Display>::fmt(self, f)
41    }
42}
43
44impl StdError for ParseError { }