mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
attention: Simplify the payload type, and add a serialise function.
This commit is contained in:
parent
ca6e65ad76
commit
54f4040251
1 changed files with 16 additions and 4 deletions
|
@ -5,9 +5,7 @@ use error::Error;
|
|||
use ns;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Attention {
|
||||
Attention,
|
||||
}
|
||||
pub struct Attention;
|
||||
|
||||
pub fn parse_attention(root: &Element) -> Result<Attention, Error> {
|
||||
if !root.is("attention", ns::ATTENTION) {
|
||||
|
@ -16,7 +14,13 @@ pub fn parse_attention(root: &Element) -> Result<Attention, Error> {
|
|||
for _ in root.children() {
|
||||
return Err(Error::ParseError("Unknown child in attention element."));
|
||||
}
|
||||
Ok(Attention::Attention)
|
||||
Ok(Attention)
|
||||
}
|
||||
|
||||
pub fn serialise(_: &Attention) -> Element {
|
||||
Element::builder("attention")
|
||||
.ns(ns::ATTENTION)
|
||||
.build()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -41,4 +45,12 @@ mod tests {
|
|||
};
|
||||
assert_eq!(message, "Unknown child in attention element.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialise() {
|
||||
let elem: Element = "<attention xmlns='urn:xmpp:attention:0'/>".parse().unwrap();
|
||||
let attention = attention::Attention;
|
||||
let elem2 = attention::serialise(&attention);
|
||||
assert_eq!(elem, elem2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue