dust_mail/client/
content.rs1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug)]
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6pub struct Content {
7 pub(crate) text: Option<String>,
8 pub(crate) html: Option<String>,
9}
10
11impl<T: Into<String>> From<T> for Content {
12 fn from(text: T) -> Self {
13 Self::from_text(text)
14 }
15}
16
17impl Default for Content {
18 fn default() -> Self {
19 Self {
20 html: None,
21 text: None,
22 }
23 }
24}
25
26impl Content {
27 pub fn new(text: Option<String>, html: Option<String>) -> Self {
28 Self { text, html }
29 }
30
31 pub fn from_text<T: Into<String>>(text: T) -> Self {
32 Self::new(Some(text.into()), None)
33 }
34
35 pub fn set_text<T: Into<String>>(&mut self, text: T) {
36 self.text = Some(text.into())
37 }
38
39 pub fn set_html<H: Into<String>>(&mut self, html: H) {
40 self.html = Some(html.into())
41 }
42
43 pub fn text(&self) -> Option<&str> {
45 match &self.text {
46 Some(text) => Some(text),
47 None => None,
48 }
49 }
50
51 pub fn html(&self) -> Option<&str> {
53 match &self.html {
54 Some(html) => Some(html),
55 None => None,
56 }
57 }
58}