Skip to main content

ical/tree/param/
feature.rs

1//! # FEATURE parameter lens
2//!
3//! The `FEATURE` parameter lens: the conference feature set (RFC 7986 6.3).
4
5use alloc::{borrow::Cow, string::ToString, vec::Vec};
6
7use crate::{
8    param::IcalParamKind,
9    tree::{
10        codec::unescape::unescape,
11        leaf::IcalLeaf,
12        param::{IcalParamLens, IcalParamNode},
13    },
14};
15
16/// The `FEATURE` parameter lens.
17#[allow(non_camel_case_types)]
18pub struct FEATURE;
19
20impl IcalParamLens for FEATURE {
21    const KIND: IcalParamKind = IcalParamKind::Feature;
22
23    type Target<'v> = Vec<Cow<'v, str>>;
24
25    fn decode<'v>(param: &'v IcalParamNode<'_>) -> Vec<Cow<'v, str>> {
26        param
27            .values
28            .iter()
29            .map(|value| unescape(value.get()))
30            .collect()
31    }
32
33    #[allow(clippy::ptr_arg)]
34    fn encode(decoded: &Vec<Cow<'_, str>>) -> IcalParamNode<'static> {
35        IcalParamNode {
36            name: IcalLeaf::from(Self::KIND.to_string()),
37            values: decoded
38                .iter()
39                .map(|value| IcalLeaf::from(value.to_string()))
40                .collect(),
41        }
42    }
43}