eml_parser/
errors.rs

1use std::{error, fmt, io};
2
3#[derive(Debug)]
4pub enum EmlError {
5    UnexpectedEndOfStream(String),
6    UnexpectedContent(String),
7    IoError(std::io::Error),
8}
9
10impl From<io::Error> for EmlError {
11    fn from(inner: io::Error) -> Self {
12        EmlError::IoError(inner)
13    }
14}
15
16impl fmt::Display for EmlError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            EmlError::UnexpectedEndOfStream(s) => write!(f, "Unexpected end of stream: {}", s),
20            EmlError::UnexpectedContent(s) => write!(f, "Unexpected content: {}", s),
21            EmlError::IoError(inner) => write!(f, "IO error: {}", inner),
22        }
23    }
24}
25
26impl error::Error for EmlError {
27    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
28        match self {
29            EmlError::IoError(inner) => Some(inner),
30            _ => None,
31        }
32    }
33}