1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
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<String>,
items: Vec<Item>,
}
impl FromElement for Query {
fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
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<String>,
node: Option<String>,
}
impl FromElement for Item {
fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
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())
}
}
|