mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
delay: Simplify parsing and add more checks.
This commit is contained in:
parent
7950fe8f52
commit
35258482ba
1 changed files with 5 additions and 10 deletions
15
src/delay.rs
15
src/delay.rs
|
@ -25,21 +25,16 @@ impl TryFrom<Element> for Delay {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Delay, Error> {
|
fn try_from(elem: Element) -> Result<Delay, Error> {
|
||||||
if !elem.is("delay", ns::DELAY) {
|
check_self!(elem, "delay", ns::DELAY);
|
||||||
return Err(Error::ParseError("This is not a delay element."));
|
check_no_children!(elem, "delay");
|
||||||
}
|
check_no_unknown_attributes!(elem, "delay", ["from", "stamp"]);
|
||||||
for _ in elem.children() {
|
|
||||||
return Err(Error::ParseError("Unknown child in delay element."));
|
|
||||||
}
|
|
||||||
let from = get_attr!(elem, "from", optional);
|
|
||||||
let stamp = get_attr!(elem, "stamp", required);
|
|
||||||
let data = match elem.text().as_ref() {
|
let data = match elem.text().as_ref() {
|
||||||
"" => None,
|
"" => None,
|
||||||
text => Some(text.to_owned()),
|
text => Some(text.to_owned()),
|
||||||
};
|
};
|
||||||
Ok(Delay {
|
Ok(Delay {
|
||||||
from: from,
|
from: get_attr!(elem, "from", optional),
|
||||||
stamp: stamp,
|
stamp: get_attr!(elem, "stamp", required),
|
||||||
data: data,
|
data: data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue