email_parser/
error.rs

1#[derive(Debug, PartialEq, Clone)]
2pub enum Error {
3    Unknown(&'static str),
4    TagError(&'static str),
5    DuplicateHeader(&'static str),
6    MissingHeader(&'static str),
7}
8
9impl std::fmt::Display for Error {
10    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11        match self {
12            Error::Unknown(message) => write!(f, "{}", message),
13            Error::TagError(expected) => write!(f, "A {:?} is missing in the mail.", expected),
14            Error::DuplicateHeader(name) => {
15                write!(f, "There are too many {} headers in this mail.", name)
16            }
17            Error::MissingHeader(name) => write!(f, "A valid {} header is required.", name),
18        }
19    }
20}
21
22impl std::error::Error for Error {}
23
24pub type Res<'a, T> = Result<(&'a [u8], T), Error>;