Skip to main content

ical/value/
text.rs

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