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
use self::Error::*;
use std::{
    error::Error as StdError,
    fmt::{self, Display, Formatter},
};

/// Error type for email content
#[derive(Debug, Clone, Copy)]
pub enum Error {
    /// Missing from in envelope
    MissingFrom,
    /// Missing to in envelope
    MissingTo,
    /// Invalid email
    InvalidEmailAddress,
}

impl Display for Error {
    fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
        fmt.write_str(&match *self {
            MissingFrom => "missing source address, invalid envelope".to_owned(),
            MissingTo => "missing destination address, invalid envelope".to_owned(),
            InvalidEmailAddress => "invalid email address".to_owned(),
        })
    }
}

impl StdError for Error {
    fn cause(&self) -> Option<&dyn StdError> {
        None
    }
}

/// Email result type
pub type EmailResult<T> = Result<T, Error>;