aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/xep_0390.rs
blob: 1a079c29d5f295f9033008c3588d5296e4bd73d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::xep_0300::Hash;
use peanuts::{Element, FromElement, IntoElement};

pub const XMLNS: &str = "urn:xmpp:caps";

// TODO: have a vec which guarantees at least one item
#[derive(Debug, Clone)]
pub struct C(pub Vec<Hash>);

impl FromElement for C {
    fn from_element(mut element: Element) -> peanuts::DeserializeResult<Self> {
        element.check_name("c")?;
        element.check_namespace(XMLNS)?;

        Ok(Self(element.pop_children()?))
    }
}

impl IntoElement for C {
    fn builder(&self) -> peanuts::ElementBuilder {
        Element::builder("c", Some(XMLNS)).push_children(self.0.clone())
    }
}