Skip to main content

ical/value/
duration.rs

1//! # Duration value
2//!
3//! The decoded duration value kind.
4//!
5//! Backs `DURATION` and the duration form of other properties (RFC 5545
6//! 3.3.6): an ISO 8601 duration such as `P15DT5H0M20S` or `-P1D`, always
7//! prefixed by `P` (with an optional leading sign). The value is kept as its
8//! raw text; the crate does not parse it into day/hour/minute/second
9//! components. Pure data, no escaping; the owning property's wire name lives on
10//! [`crate::prop::IcalProp::name`].
11
12use alloc::{borrow::Cow, string::String};
13
14/// A decoded duration value (ISO 8601 `P...`), kept as its raw text.
15#[derive(Clone, Debug, Default, PartialEq, Eq)]
16pub struct IcalDuration<'a>(pub Cow<'a, str>);
17
18impl<'a> From<&'a str> for IcalDuration<'a> {
19    fn from(value: &'a str) -> Self {
20        Self(Cow::Borrowed(value))
21    }
22}
23
24impl From<String> for IcalDuration<'_> {
25    fn from(value: String) -> Self {
26        Self(Cow::Owned(value))
27    }
28}
29
30impl<'a> From<Cow<'a, str>> for IcalDuration<'a> {
31    fn from(value: Cow<'a, str>) -> Self {
32        Self(value)
33    }
34}