From a0c95f748ed39467100ddda24698df8629b95369 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Tue, 17 Apr 2018 00:21:43 +0200 Subject: [PATCH] feat(transport): Use an associated type for result type of EmailTransport --- lettre/src/file/mod.rs | 4 +++- lettre/src/lib.rs | 7 +++++-- lettre/src/sendmail/mod.rs | 4 +++- lettre/src/smtp/mod.rs | 4 +++- lettre/src/stub/mod.rs | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lettre/src/file/mod.rs b/lettre/src/file/mod.rs index fcb80f6..db94f3a 100644 --- a/lettre/src/file/mod.rs +++ b/lettre/src/file/mod.rs @@ -31,7 +31,9 @@ impl FileEmailTransport { } } -impl<'a, T: Read + 'a> EmailTransport<'a, T, FileResult> for FileEmailTransport { +impl<'a, T: Read + 'a> EmailTransport<'a, T> for FileEmailTransport { + type Result = FileResult; + fn send + 'a>(&mut self, email: &'a U) -> FileResult { let mut file = self.path.clone(); file.push(format!("{}.txt", email.message_id())); diff --git a/lettre/src/lib.rs b/lettre/src/lib.rs index 47b4028..d688a76 100644 --- a/lettre/src/lib.rs +++ b/lettre/src/lib.rs @@ -212,9 +212,12 @@ pub trait SendableEmail<'a, T: Read + 'a> { } /// Transport method for emails -pub trait EmailTransport<'a, U: Read + 'a, V> { +pub trait EmailTransport<'a, U: Read + 'a> { + /// Result type for the transport + type Result; + /// Sends the email - fn send + 'a>(&mut self, email: &'a T) -> V; + fn send + 'a>(&mut self, email: &'a T) -> Self::Result; } /// Minimal email structure diff --git a/lettre/src/sendmail/mod.rs b/lettre/src/sendmail/mod.rs index a40d9d6..018b6bd 100644 --- a/lettre/src/sendmail/mod.rs +++ b/lettre/src/sendmail/mod.rs @@ -32,7 +32,9 @@ impl SendmailTransport { } } -impl<'a, T: Read + 'a> EmailTransport<'a, T, SendmailResult> for SendmailTransport { +impl<'a, T: Read + 'a> EmailTransport<'a, T> for SendmailTransport { + type Result = SendmailResult; + fn send + 'a>(&mut self, email: &'a U) -> SendmailResult { let envelope = email.envelope(); diff --git a/lettre/src/smtp/mod.rs b/lettre/src/smtp/mod.rs index bec5480..4d7cba2 100644 --- a/lettre/src/smtp/mod.rs +++ b/lettre/src/smtp/mod.rs @@ -306,7 +306,9 @@ impl<'a> SmtpTransport { } } -impl<'a, T: Read + 'a> EmailTransport<'a, T, SmtpResult> for SmtpTransport { +impl<'a, T: Read + 'a> EmailTransport<'a, T> for SmtpTransport { + type Result = SmtpResult; + /// Sends an email #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms, cyclomatic_complexity))] fn send + 'a>(&mut self, email: &'a U) -> SmtpResult { diff --git a/lettre/src/stub/mod.rs b/lettre/src/stub/mod.rs index 2e6247c..efa7034 100644 --- a/lettre/src/stub/mod.rs +++ b/lettre/src/stub/mod.rs @@ -27,7 +27,9 @@ impl StubEmailTransport { /// SMTP result type pub type StubResult = Result<(), ()>; -impl<'a, T: Read + 'a> EmailTransport<'a, T, StubResult> for StubEmailTransport { +impl<'a, T: Read + 'a> EmailTransport<'a, T> for StubEmailTransport { + type Result = StubResult; + fn send>(&mut self, email: &'a U) -> StubResult { let envelope = email.envelope(); info!(