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 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`].
9//!
10//! Carrying no wire name, the same value type round-trips through any
11//! property that shares the kind.
12
13use alloc::{borrow::Cow, string::String, vec::Vec};
14
15/// A single decoded text value (unescaped).
16#[derive(Clone, Debug, Default, PartialEq, Eq)]
17pub struct IcalText<'a>(pub Cow<'a, str>);
18
19impl<'a> From<&'a str> for IcalText<'a> {
20    fn from(value: &'a str) -> Self {
21        Self(Cow::Borrowed(value))
22    }
23}
24
25impl From<String> for IcalText<'_> {
26    fn from(value: String) -> Self {
27        Self(Cow::Owned(value))
28    }
29}
30
31impl<'a> From<Cow<'a, str>> for IcalText<'a> {
32    fn from(value: Cow<'a, str>) -> Self {
33        Self(value)
34    }
35}
36
37/// A decoded comma-separated text list (each item unescaped).
38#[derive(Clone, Debug, Default, PartialEq, Eq)]
39pub struct IcalTextList<'a>(pub Vec<Cow<'a, str>>);
40
41impl<'a> From<Vec<Cow<'a, str>>> for IcalTextList<'a> {
42    fn from(values: Vec<Cow<'a, str>>) -> Self {
43        Self(values)
44    }
45}