ical-rs 0.3.0

iCalendar parser, validator, editor, merger and builder library
Documentation
//! # Property lens contract
//!
//! [`IcalPropLens`] ties a property (by type) to its decoded value type, an
//! edit cursor, and the `decode` projection from the generic syntax node onto
//! the type.
//!
//! The wire name comes from its [`IcalPropSpec::KIND`] supertrait, so the two
//! stay in sync; each property implements it on the marker it defines in
//! [`crate::prop`].

use crate::{
    prop::spec::IcalPropSpec,
    tree::{codec::Codec, line::IcalLine},
    version::IcalVersion,
};

/// A property identified by type: its decoded value type, edit cursor, and the
/// `decode` projection from the generic syntax node onto the type. The wire
/// name comes from its [`IcalPropSpec::KIND`] (a supertrait), so the two stay
/// in sync.
pub trait IcalPropLens: IcalPropSpec {
    /// The decoded value type, borrowing the syntax node for reads. Its
    /// [`Codec`] impl is what the default `decode` delegates to.
    type Target<'v>: Codec<'v>;

    /// The typed edit cursor over a content line.
    type Cursor<'c, 'a>
    where
        'a: 'c;

    /// Project a content line onto the decoded type, consulting the calendar
    /// version where the value's shape is version-specific (`GEO`, the binary
    /// props). The default ignores the version and decodes the value node
    /// through the target's [`Codec`]; the version-specific lenses override it.
    fn decode<'v>(line: &'v IcalLine<'_>, _version: IcalVersion) -> Self::Target<'v> {
        <Self::Target<'v> as Codec<'v>>::decode(&line.value)
    }

    /// Wrap a content line in the typed cursor for in-place editing.
    fn cursor<'c, 'a>(line: &'c mut IcalLine<'a>) -> Self::Cursor<'c, 'a>;
}