Skip to main content

ical/tree/value/
request_status.rs

1//! # REQUEST-STATUS value codec (RFC 5545 3.8.8.3)
2//!
3//! [`Codec`] for the structured `REQUEST-STATUS` value: a
4//! `code;description;extra` triple, held as three `;`-separated components (the
5//! third is optional and decodes to an empty value when absent).
6
7use alloc::vec;
8
9use crate::{
10    tree::{
11        codec::{Codec, encode::encode_component, mode::Escaper},
12        value::node::IcalValueNode,
13    },
14    value::request_status::IcalRequestStatus,
15};
16
17impl<'v> Codec<'v> for IcalRequestStatus<'v> {
18    fn decode(node: &'v IcalValueNode<'_>) -> Self {
19        IcalRequestStatus {
20            code: node.decode_component(0),
21            description: node.decode_component(1),
22            extra: node.decode_component(2),
23        }
24    }
25
26    fn encode(&self, escaper: Escaper) -> IcalValueNode<'static> {
27        IcalValueNode::from_components(
28            vec![
29                encode_component(&[self.code.as_ref()], escaper),
30                encode_component(&[self.description.as_ref()], escaper),
31                encode_component(&[self.extra.as_ref()], escaper),
32            ],
33            escaper,
34        )
35    }
36}