samotop_core/mail/
builder.rs1use crate::{mail::*, smtp::*};
2use std::ops::{Add, AddAssign};
3
4#[derive(Default, Debug)]
10pub struct Builder;
11
12impl<T: MailSetup<Configuration>> Add<T> for Builder {
14 type Output = BuilderWithConfig;
15 fn add(self, setup: T) -> Self::Output {
17 BuilderWithConfig::default() + setup
18 }
19}
20
21impl Builder {
22 pub fn empty() -> BuilderWithConfig {
24 BuilderWithConfig::default()
25 }
26 pub fn using(self, setup: impl MailSetup<Configuration>) -> BuilderWithConfig {
30 BuilderWithConfig::default() + setup
31 }
32 #[cfg(feature = "driver")]
33 pub fn build(self) -> Service {
35 BuilderWithConfig::default().build()
36 }
37}
38
39#[derive(Default)]
41pub struct BuilderWithConfig {
42 config: Configuration,
43}
44
45impl<T: MailSetup<Configuration>> Add<T> for BuilderWithConfig {
47 type Output = Self;
48 fn add(mut self, setup: T) -> Self::Output {
50 self += setup;
51 self
52 }
53}
54impl<T: MailSetup<Configuration>> AddAssign<T> for BuilderWithConfig {
56 fn add_assign(&mut self, setup: T) {
57 trace!(
58 "Service builder {} using setup {:?}",
59 self.config.id(),
60 setup
61 );
62 setup.setup(&mut self.config)
63 }
64}
65
66impl BuilderWithConfig {
67 pub fn using(self, setup: impl MailSetup<Configuration>) -> Self {
71 self + setup
72 }
73
74 #[cfg(feature = "driver")]
75 pub fn build(self) -> Service {
77 self.build_with_driver(crate::smtp::SmtpDriver)
78 }
79
80 pub fn build_with_driver(self, driver: impl Drive + Send + Sync + 'static) -> Service {
82 self.config.into_service(driver)
83 }
84}