From 66fb8fea74894d4f33498b11ffd219e1d36b6e5e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 10 Oct 2017 18:00:15 +0100 Subject: [PATCH] message_correct: Use the new helper macros to simplify parsing. --- src/message_correct.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/message_correct.rs b/src/message_correct.rs index bb5c2b2..d8200ae 100644 --- a/src/message_correct.rs +++ b/src/message_correct.rs @@ -21,17 +21,9 @@ impl TryFrom for Replace { type Err = Error; fn try_from(elem: Element) -> Result { - if !elem.is("replace", ns::MESSAGE_CORRECT) { - return Err(Error::ParseError("This is not a replace element.")); - } - for _ in elem.children() { - return Err(Error::ParseError("Unknown child in replace element.")); - } - for (attr, _) in elem.attrs() { - if attr != "id" { - return Err(Error::ParseError("Unknown attribute in replace element.")); - } - } + check_self!(elem, "replace", ns::MESSAGE_CORRECT); + check_no_children!(elem, "replace"); + check_no_unknown_attributes!(elem, "replace", ["id"]); let id = get_attr!(elem, "id", required); Ok(Replace { id }) }