Skip to main content

ical/tree/param/
member.rs

1//! # MEMBER parameter lens
2//!
3//! The `MEMBER` parameter lens: the group memberships (RFC 5545 3.2.11).
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::{lens::IcalParamLens, node::IcalParamNode},
13    },
14};
15
16/// The `MEMBER` parameter lens.
17#[allow(non_camel_case_types)]
18pub struct MEMBER;
19
20impl IcalParamLens for MEMBER {
21    const KIND: IcalParamKind = IcalParamKind::Member;
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}