vcard-rs 0.2.1

vCard parser, validator, editor and builder library for Rust
Documentation
//! # SOCIALPROFILE lens
//!
//! The `SOCIALPROFILE` property lens: a social-media profile, a URI by
//! default or a username when `VALUE=text` is declared, so the lens decodes
//! through the property spec like the other multi-kind lenses.
//!
//! See RFC 9554.

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

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

impl VcardPropLens for SOCIALPROFILE {
    type Target<'v> = VcardValue<'v>;

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

    fn decode<'v>(line: &'v VcardLine<'_>, version: VcardVersion) -> VcardValue<'v> {
        line.decode_value(VcardPropKind::SocialProfile, version)
    }

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

impl VcardPropSpec for SOCIALPROFILE {
    const KIND: VcardPropKind = VcardPropKind::SocialProfile;

    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::ServiceType,
            VcardParamKind::Username,
            VcardParamKind::Pref,
            VcardParamKind::Type,
            VcardParamKind::AltId,
            VcardParamKind::Value,
        ]
    }
}