Merge pull request #367 from gralpli/issue-362

fix(all): accept `Into<SendableEmail>`
This commit is contained in:
Alexis Mousset
2019-11-30 09:58:20 +00:00
committed by GitHub
7 changed files with 15 additions and 7 deletions

View File

@@ -67,7 +67,7 @@ fn main() {
// Open a local connection on port 25
let mut mailer = SmtpClient::new_unencrypted_localhost().unwrap().transport();
// Send the email
let result = mailer.send(email.into());
let result = mailer.send(email);
if result.is_ok() {
println!("Email sent");

View File

@@ -47,7 +47,9 @@ struct SerializableEmail {
impl<'a> Transport<'a> for FileTransport {
type Result = FileResult;
fn send(&mut self, email: SendableEmail) -> FileResult {
fn send<E: Into<SendableEmail>>(&mut self, email: E) -> FileResult {
let email = email.into();
let message_id = email.message_id().to_string();
let envelope = email.envelope().clone();

View File

@@ -192,5 +192,5 @@ pub trait Transport<'a> {
type Result;
/// Sends the email
fn send(&mut self, email: SendableEmail) -> Self::Result;
fn send<E: Into<SendableEmail>>(&mut self, email: E) -> Self::Result;
}

View File

@@ -41,7 +41,9 @@ impl SendmailTransport {
impl<'a> Transport<'a> for SendmailTransport {
type Result = SendmailResult;
fn send(&mut self, email: SendableEmail) -> SendmailResult {
fn send<E: Into<SendableEmail>>(&mut self, email: E) -> SendmailResult {
let email = email.into();
let message_id = email.message_id().to_string();
// Spawn the sendmail command

View File

@@ -407,7 +407,9 @@ impl<'a> Transport<'a> for SmtpTransport {
feature = "cargo-clippy",
allow(clippy::match_same_arms, clippy::cyclomatic_complexity)
)]
fn send(&mut self, email: SendableEmail) -> SmtpResult {
fn send<E: Into<SendableEmail>>(&mut self, email: E) -> SmtpResult {
let email = email.into();
let message_id = email.message_id().to_string();
if !self.client.is_connected() {

View File

@@ -30,7 +30,9 @@ pub type StubResult = Result<(), ()>;
impl<'a> Transport<'a> for StubTransport {
type Result = StubResult;
fn send(&mut self, email: SendableEmail) -> StubResult {
fn send<E: Into<SendableEmail>>(&mut self, email: E) -> StubResult {
let email = email.into();
info!(
"{}: from=<{}> to=<{:?}>",
email.message_id(),

View File

@@ -22,7 +22,7 @@ fn main() {
// Open a local connection on port 25
let mut mailer = SmtpClient::new_unencrypted_localhost().unwrap().transport();
// Send the email
let result = mailer.send(email.into());
let result = mailer.send(email);
if result.is_ok() {
println!("Email sent");