ical/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 5545 properties whose value is plain text (the
7//! TEXT value type, RFC 5545 3.3.11): `SUMMARY`, `DESCRIPTION`, `LOCATION`,
8//! `COMMENT`, `PRODID`, `UID`, `TZID`, ... for [`IcalText`], and `CATEGORIES` /
9//! `RESOURCES` for [`IcalTextList`]. They are pure, always-unescaped data; the
10//! escaping and the wire framing live entirely on the syntax side
11//! ([`crate::tree`]), so the same value type round-trips through any property
12//! that shares the kind. The wire name that distinguishes those properties is
13//! carried by [`crate::prop::IcalProp::name`], not here.
14
15use alloc::{borrow::Cow, string::String, vec::Vec};
16
17/// A single decoded text value (unescaped).
18#[derive(Clone, Debug, Default, PartialEq, Eq)]
19pub struct IcalText<'a>(pub Cow<'a, str>);
20
21impl<'a> From<&'a str> for IcalText<'a> {
22 fn from(value: &'a str) -> Self {
23 Self(Cow::Borrowed(value))
24 }
25}
26
27impl From<String> for IcalText<'_> {
28 fn from(value: String) -> Self {
29 Self(Cow::Owned(value))
30 }
31}
32
33impl<'a> From<Cow<'a, str>> for IcalText<'a> {
34 fn from(value: Cow<'a, str>) -> Self {
35 Self(value)
36 }
37}
38
39/// A decoded comma-separated text list (each item unescaped).
40#[derive(Clone, Debug, Default, PartialEq, Eq)]
41pub struct IcalTextList<'a>(pub Vec<Cow<'a, str>>);
42
43impl<'a> From<Vec<Cow<'a, str>>> for IcalTextList<'a> {
44 fn from(values: Vec<Cow<'a, str>>) -> Self {
45 Self(values)
46 }
47}