use peanuts::{ element::{FromElement, IntoElement}, Element, }; pub const XMLNS: &str = "http://jabber.org/protocol/nick"; #[derive(Debug, Clone)] pub struct Nick(pub String); impl FromElement for Nick { fn from_element(mut element: peanuts::Element) -> peanuts::element::DeserializeResult { element.check_name("nick")?; element.check_namespace(XMLNS)?; Ok(Self(element.pop_value_opt()?.unwrap_or_default())) } } impl IntoElement for Nick { fn builder(&self) -> peanuts::element::ElementBuilder { let builder = Element::builder("nick", Some(XMLNS)); if self.0.is_empty() { builder } else { builder.push_text(self.0.clone()) } } }