summaryrefslogtreecommitdiffstats
path: root/mail/examples/mail_from_template/error.rs
blob: 21bccfed11d0714d6fd99ef4d5cb4b28dd937dc2 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use mail::error::{CompositionError, ComponentCreationError};
use mail::render_template_engine::error::{CreatingSpecError, InsertionError as _InsertionError};
use mail::tera::error::TeraError;

type InsertionError = _InsertionError<TeraError>;

#[derive(Fail, Debug)]
pub enum SetupError {
    #[fail(display = "{}", _0)]
    Tera(TeraError),

    #[fail(display = "{}", _0)]
    CreatingSpecs(CreatingSpecError),

    #[fail(display = "{}", _0)]
    UsingSpecs(InsertionError)
}

impl From<TeraError> for SetupError {
    fn from(err: TeraError) -> Self {
        SetupError::Tera(err)
    }
}
impl From<InsertionError> for SetupError {
    fn from(err: InsertionError) -> Self {
        SetupError::UsingSpecs(err)
    }
}

impl From<CreatingSpecError> for SetupError {
    fn from(err: CreatingSpecError) -> Self {
        SetupError::CreatingSpecs(err)
    }
}

// TODO `Header` should be mergeable into `Composition`.
#[derive(Fail, Debug)]
pub enum Error {
    #[fail(display = "{}", _0)]
    Composition(CompositionError<TeraError>),
    #[fail(display = "{}", _0)]
    Header(ComponentCreationError)
}

impl From<CompositionError<TeraError>> for Error {
    fn from(err: CompositionError<TeraError>) -> Self {
        Error::Composition(err)
    }
}

impl From<ComponentCreationError> for Error {
    fn from(err: ComponentCreationError) -> Self {
        Error::Header(err)
    }
}