Skip to content

Commit 52f2f0c

Browse files
authored
email: Reduce monomorphization overhead for the Emails::build_message() fn (#10304)
1 parent 9127efd commit 52f2f0c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/email.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ impl Emails {
8484
}
8585
}
8686

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

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

103-
let subject = email.subject();
104-
let body = email.body();
105-
106108
let message = Message::builder()
107109
.message_id(Some(message_id.clone()))
108110
.to(recipient.parse()?)
@@ -115,7 +117,7 @@ impl Emails {
115117
}
116118

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

120122
self.backend
121123
.send(email)

0 commit comments

Comments
 (0)