Skip to content

Commit

Permalink
email: Reduce monomorphization overhead for the `Emails::build_messag…
Browse files Browse the repository at this point in the history
…e()` fn (#10304)
  • Loading branch information
Turbo87 authored Jan 2, 2025
1 parent 9127efd commit 52f2f0c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ impl Emails {
}
}

fn build_message<E: Email>(&self, recipient: &str, email: E) -> Result<Message, EmailError> {
fn build_message(
&self,
recipient: &str,
subject: String,
body: String,
) -> Result<Message, EmailError> {
// The message ID is normally generated by the SMTP server, but if we let it generate the
// ID there will be no way for the crates.io application to know the ID of the message it
// just sent, as it's not included in the SMTP response.
Expand All @@ -100,9 +105,6 @@ impl Emails {

let from = Mailbox::new(Some(self.domain.clone()), self.from.clone());

let subject = email.subject();
let body = email.body();

let message = Message::builder()
.message_id(Some(message_id.clone()))
.to(recipient.parse()?)
Expand All @@ -115,7 +117,7 @@ impl Emails {
}

pub async fn send<E: Email>(&self, recipient: &str, email: E) -> Result<(), EmailError> {
let email = self.build_message(recipient, email)?;
let email = self.build_message(recipient, email.subject(), email.body())?;

self.backend
.send(email)
Expand Down

0 comments on commit 52f2f0c

Please sign in to comment.