use alloc::borrow::Cow;
use crate::{
prop::gender::GENDER,
tree::{
codec::VcardCodec, line::VcardLine, param::lens::VcardParamLens, prop::lens::VcardPropLens,
},
value::gender::VcardGender,
};
impl VcardPropLens for GENDER {
type Target<'v> = VcardGender<'v>;
type Cursor<'c, 'a>
= VcardGenderCursor<'c, 'a>
where
'a: 'c;
fn cursor<'c, 'a>(line: &'c mut VcardLine<'a>) -> VcardGenderCursor<'c, 'a> {
VcardGenderCursor { line }
}
}
pub struct VcardGenderCursor<'c, 'a> {
pub line: &'c mut VcardLine<'a>,
}
impl VcardGenderCursor<'_, '_> {
pub fn get(&self) -> VcardGender<'_> {
VcardGender::decode(&self.line.value)
}
pub fn sex(&self) -> Cow<'_, str> {
self.line.value.decode_component(0)
}
pub fn set_sex(&mut self, value: impl AsRef<str>) {
self.line.value.set_component(0, &[value]);
}
pub fn identity(&self) -> Cow<'_, str> {
self.line.value.decode_component(1)
}
pub fn set_identity(&mut self, value: impl AsRef<str>) {
self.line.value.set_component(1, &[value]);
}
pub fn param<P: VcardParamLens>(&self) -> Option<P::Target<'_>> {
self.line.param::<P>()
}
}