From 5434b2d26e7285a89146b708a710962b096b05bf Mon Sep 17 00:00:00 2001 From: Mauro D Date: Wed, 7 Jun 2023 16:33:28 +0000 Subject: [PATCH] EmailBodyPart Get from Set --- src/email/set.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/email/set.rs b/src/email/set.rs index f99a022..b3458a1 100644 --- a/src/email/set.rs +++ b/src/email/set.rs @@ -167,20 +167,24 @@ impl Email { self } - pub fn text_body(&mut self, text_body: EmailBodyPart) -> &mut Self { - self.text_body.get_or_insert_with(Vec::new).push(text_body); + pub fn text_body(&mut self, text_body: impl Into>) -> &mut Self { + self.text_body + .get_or_insert_with(Vec::new) + .push(text_body.into()); self } - pub fn html_body(&mut self, html_body: EmailBodyPart) -> &mut Self { - self.html_body.get_or_insert_with(Vec::new).push(html_body); + pub fn html_body(&mut self, html_body: impl Into>) -> &mut Self { + self.html_body + .get_or_insert_with(Vec::new) + .push(html_body.into()); self } - pub fn attachment(&mut self, attachment: EmailBodyPart) -> &mut Self { + pub fn attachment(&mut self, attachment: impl Into>) -> &mut Self { self.attachments .get_or_insert_with(Vec::new) - .push(attachment); + .push(attachment.into()); self } @@ -271,6 +275,27 @@ impl EmailBodyPart { } } +impl From> for EmailBodyPart { + fn from(part: EmailBodyPart) -> Self { + EmailBodyPart { + part_id: part.part_id, + blob_id: part.blob_id, + size: part.size, + headers: part.headers, + name: part.name, + type_: part.type_, + charset: part.charset, + disposition: part.disposition, + cid: part.cid, + language: part.language, + location: part.location, + sub_parts: part.sub_parts, + header: part.header, + _state: Default::default(), + } + } +} + impl EmailBodyPart { pub fn part_id(mut self, part_id: impl Into) -> Self { self.part_id = Some(part_id.into());