Skip to main content

vcard/tree/value/
gender.rs

1//! # GENDER value codec (RFC 6350 6.2.7)
2//!
3//! [`VcardCodec`] for the structured gender: a sex component and an identity
4//! component.
5
6use alloc::vec;
7
8use crate::{
9    tree::{
10        codec::{VcardCodec, encode::encode_component, mode::VcardEscaper},
11        value::node::VcardValueNode,
12    },
13    value::gender::VcardGender,
14};
15
16impl<'v> VcardCodec<'v> for VcardGender<'v> {
17    fn decode(node: &'v VcardValueNode<'_>) -> Self {
18        VcardGender {
19            sex: node.decode_scalar_at(0),
20            identity: node.decode_scalar_at(1),
21        }
22    }
23
24    fn encode(&self, escaper: VcardEscaper) -> VcardValueNode<'static> {
25        VcardValueNode::from_components(
26            vec![
27                encode_component(&[self.sex.as_ref()], escaper),
28                encode_component(&[self.identity.as_ref()], escaper),
29            ],
30            escaper,
31        )
32    }
33}