ical-rs 0.5.1

iCalendar parser, validator, editor, merger and builder library
Documentation
//! # Calendar
//!
//! The decoded calendar: a version plus the `VCALENDAR`'s properties and nested
//! components.
//!
//! [`Ical`] is the top of the decoded model, the semantic counterpart of a
//! whole [`IcalCst`](crate::tree::cst::IcalCst). It is a `VCALENDAR` with its
//! [`version`](Ical::version) hoisted out of the property list: the `VERSION`
//! line is the envelope indicator, not a free property.
//!
//! What remains is its calendar-level [`props`](Ical::props) (`PRODID`,
//! `CALSCALE`, `METHOD`, ...) and its nested [`components`](Ical::components)
//! (`VEVENT`, `VTODO`, `VTIMEZONE`, ...), each a recursive [`IcalComponent`].
//!
//! Build a calendar directly from its public fields; strict construction is
//! the [`builder`](crate::builder) and conformance checking the
//! [`validator`](crate::validator). Pure model, no [`crate::tree`].
//!
//! [`IcalComponent`]: crate::component::IcalComponent

use alloc::vec::Vec;

use crate::{component::IcalComponent, prop::IcalProp, version::IcalVersion};

/// A decoded calendar: a `VCALENDAR` with its version hoisted out.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Ical<'a> {
    /// The calendar version, read from the `VERSION` property.
    pub version: IcalVersion,
    /// The calendar-level properties (`PRODID`, `CALSCALE`, `METHOD`, ...),
    /// excluding `VERSION`.
    pub props: Vec<IcalProp<'a>>,
    /// The components nested in the calendar (`VEVENT`, `VTODO`, `VTIMEZONE`,
    /// ...), in source order.
    pub components: Vec<IcalComponent<'a>>,
}

impl Ical<'_> {
    /// The same calendar with every borrow replaced by an allocation, so it
    /// outlives the bytes it was decoded from. See
    /// [`IcalValue::into_owned`](crate::value::IcalValue::into_owned).
    pub fn into_owned(self) -> Ical<'static> {
        Ical {
            version: self.version,
            props: self.props.into_iter().map(IcalProp::into_owned).collect(),
            components: self
                .components
                .into_iter()
                .map(IcalComponent::into_owned)
                .collect(),
        }
    }
}