Merge pull request #266 from amousset/result-type-transport
feat(transport): Use an associated type for result type of EmailTrans…
This commit is contained in:
@@ -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<U: SendableEmail<'a, T> + 'a>(&mut self, email: &'a U) -> FileResult {
|
||||
let mut file = self.path.clone();
|
||||
file.push(format!("{}.txt", email.message_id()));
|
||||
|
||||
@@ -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<T: SendableEmail<'a, U> + 'a>(&mut self, email: &'a T) -> V;
|
||||
fn send<T: SendableEmail<'a, U> + 'a>(&mut self, email: &'a T) -> Self::Result;
|
||||
}
|
||||
|
||||
/// Minimal email structure
|
||||
|
||||
@@ -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<U: SendableEmail<'a, T> + 'a>(&mut self, email: &'a U) -> SendmailResult {
|
||||
let envelope = email.envelope();
|
||||
|
||||
|
||||
@@ -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<U: SendableEmail<'a, T> + 'a>(&mut self, email: &'a U) -> SmtpResult {
|
||||
|
||||
@@ -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<U: SendableEmail<'a, T>>(&mut self, email: &'a U) -> StubResult {
|
||||
let envelope = email.envelope();
|
||||
info!(
|
||||
|
||||
Reference in New Issue
Block a user