Skip to main content

vcard/value/
text.rs

1//! # Text values
2//!
3//! The decoded text value kinds: a single text, and a comma-separated text
4//! list.
5//!
6//! These back the bulk of RFC 6350 properties whose value is plain text (the
7//! TEXT value type, RFC 6350 4.1): `FN`, `TITLE`, `ROLE`, `NOTE`, `PRODID`,
8//! `KIND`, `TEL`, `EMAIL`, ... for [`VcardText`], and `NICKNAME` / `CATEGORIES`
9//! for [`VcardTextList`]. Carrying no wire name, the same value type
10//! round-trips through any property that shares the kind.
11
12use alloc::{borrow::Cow, string::String, vec::Vec};
13
14/// A single decoded text value (unescaped).
15#[derive(Clone, Debug, Default, PartialEq, Eq)]
16pub struct VcardText<'a>(pub Cow<'a, str>);
17
18impl<'a> From<&'a str> for VcardText<'a> {
19    fn from(value: &'a str) -> Self {
20        Self(Cow::Borrowed(value))
21    }
22}
23
24impl From<String> for VcardText<'_> {
25    fn from(value: String) -> Self {
26        Self(Cow::Owned(value))
27    }
28}
29
30impl<'a> From<Cow<'a, str>> for VcardText<'a> {
31    fn from(value: Cow<'a, str>) -> Self {
32        Self(value)
33    }
34}
35
36/// A decoded comma-separated text list (each item unescaped).
37#[derive(Clone, Debug, Default, PartialEq, Eq)]
38pub struct VcardTextList<'a>(pub Vec<Cow<'a, str>>);
39
40impl<'a> From<Vec<Cow<'a, str>>> for VcardTextList<'a> {
41    fn from(values: Vec<Cow<'a, str>>) -> Self {
42        Self(values)
43    }
44}