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