1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::collections::BTreeMap;

/**
 * See [3.3.11. Text](https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.11)
 */
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Text {
    pub params: BTreeMap<String, String>,
    pub text: String,
}

impl From<crate::ContentLine> for Text {
    fn from(value: crate::ContentLine) -> Self {
        Self {
            params: value.params,
            text: value.value,
        }
    }
}

impl std::fmt::Display for Text {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.text)
    }
}

impl std::ops::Deref for Text {
    type Target = str;

    fn deref(&self) -> &Self::Target {
        &self.text
    }
}

impl From<String> for Text {
    fn from(value: String) -> Self {
        Self {
            params: BTreeMap::new(),
            text: value,
        }
    }
}

impl From<&str> for Text {
    fn from(value: &str) -> Self {
        Self {
            params: BTreeMap::new(),
            text: value.to_string(),
        }
    }
}