vcard-rs 0.2.1

vCard parser, validator, editor and builder library for Rust
Documentation
//! # RELATED lens
//!
//! The `RELATED` property lens: a relationship to another entity, qualified by
//! the `TYPE` parameter. The lens decodes the value as a `VcardUri`
//! (RFC 6350 6.6.6).

use crate::{
    param::VcardParamKind,
    prop::VcardPropKind,
    tree::{
        line::VcardLine,
        prop::{lens::VcardPropLens, spec::VcardPropSpec},
        value::cursor::VcardValueCursor,
    },
    value::{VcardValueKind, uri::VcardUri},
    version::VcardVersion,
};

/// The `RELATED` property lens.
pub struct RELATED;

impl VcardPropLens for RELATED {
    type Target<'v> = VcardUri<'v>;

    type Cursor<'c, 'a>
        = VcardValueCursor<'c, 'a>
    where
        'a: 'c;

    fn cursor<'c, 'a>(line: &'c mut VcardLine<'a>) -> VcardValueCursor<'c, 'a> {
        VcardValueCursor { line }
    }
}

impl VcardPropSpec for RELATED {
    const KIND: VcardPropKind = VcardPropKind::Related;

    fn allowed_versions() -> &'static [VcardVersion] {
        &[VcardVersion::V4_0]
    }

    fn allowed_values(_version: VcardVersion) -> &'static [VcardValueKind] {
        &[VcardValueKind::Uri, VcardValueKind::Text]
    }

    fn allowed_params(_version: VcardVersion) -> &'static [VcardParamKind] {
        &[
            VcardParamKind::Type,
            VcardParamKind::Pid,
            VcardParamKind::Pref,
            VcardParamKind::AltId,
            VcardParamKind::Language,
            VcardParamKind::MediaType,
            VcardParamKind::Value,
        ]
    }
}