use jid::JID; use peanuts::{ element::{FromElement, IntoElement}, Element, }; pub const XMLNS: &str = "http://jabber.org/protocol/disco#items"; #[derive(Debug, Clone)] pub struct Query { node: Option, items: Vec, } impl FromElement for Query { fn from_element(mut element: Element) -> peanuts::element::DeserializeResult { element.check_name("query")?; element.check_namespace(XMLNS)?; let node = element.attribute_opt("node")?; let items = element.pop_children()?; Ok(Self { node, items }) } } impl IntoElement for Query { fn builder(&self) -> peanuts::element::ElementBuilder { Element::builder("query", Some(XMLNS)) .push_attribute_opt("node", self.node.clone()) .push_children(self.items.clone()) } } #[derive(Debug, Clone)] pub struct Item { jid: JID, name: Option, node: Option, } impl FromElement for Item { fn from_element(mut element: Element) -> peanuts::element::DeserializeResult { element.check_name("item")?; element.check_namespace(XMLNS)?; let jid = element.attribute("jid")?; let name = element.attribute_opt("name")?; let node = element.attribute_opt("node")?; Ok(Self { jid, name, node }) } } impl IntoElement for Item { fn builder(&self) -> peanuts::element::ElementBuilder { Element::builder("item", Some(XMLNS)) .push_attribute("jid", self.jid.clone()) .push_attribute_opt("name", self.name.clone()) .push_attribute_opt("node", self.node.clone()) } }