blob: 54846b89251f2054617c3ccefb63f2c814eb7a71 (
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
24
25
26
27
 | use peanuts::{Element, FromElement, IntoElement};
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::DeserializeResult<Self> {
        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::ElementBuilder {
        let builder = Element::builder("nick", Some(XMLNS));
        if self.0.is_empty() {
            builder
        } else {
            builder.push_text(self.0.clone())
        }
    }
}
 |