From 35258482ba6738f8cf02af254eb58d822028dfe8 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 31 Oct 2017 22:27:13 +0000 Subject: [PATCH] delay: Simplify parsing and add more checks. --- src/delay.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/delay.rs b/src/delay.rs index 53462792..e95ed4c2 100644 --- a/src/delay.rs +++ b/src/delay.rs @@ -25,21 +25,16 @@ impl TryFrom for Delay { type Err = Error; fn try_from(elem: Element) -> Result { - if !elem.is("delay", ns::DELAY) { - return Err(Error::ParseError("This is not a delay element.")); - } - 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); + check_self!(elem, "delay", ns::DELAY); + check_no_children!(elem, "delay"); + check_no_unknown_attributes!(elem, "delay", ["from", "stamp"]); let data = match elem.text().as_ref() { "" => None, text => Some(text.to_owned()), }; Ok(Delay { - from: from, - stamp: stamp, + from: get_attr!(elem, "from", optional), + stamp: get_attr!(elem, "stamp", required), data: data, }) }