aboutsummaryrefslogblamecommitdiffstats
path: root/stanza/src/xep_0084/data.rs
blob: 2a37df4df7c1096928a474aa74d5c681dc3e7553 (plain) (tree)





























                                                                                                 
use peanuts::{
    element::{FromElement, IntoElement},
    Element,
};

pub const XMLNS: &str = "urn:xmpp:avatar:data";

#[derive(Debug, Clone)]
pub struct Data(pub String);

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

        Ok(Self(element.pop_value_opt()?.unwrap_or_default()))
    }
}

impl IntoElement for Data {
    fn builder(&self) -> peanuts::element::ElementBuilder {
        let builder = Element::builder("data", Some(XMLNS));

        if self.0.is_empty() {
            builder
        } else {
            builder.push_text(self.0.clone())
        }
    }
}