From a2b603333632785b86d868e59fef4ea8131563be Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 10 Oct 2017 18:04:27 +0100 Subject: [PATCH] caps: Use the new helper macros to simplify parsing. --- src/caps.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/caps.rs b/src/caps.rs index a2bdd11..2b98679 100644 --- a/src/caps.rs +++ b/src/caps.rs @@ -33,16 +33,12 @@ impl TryFrom for Caps { type Err = Error; fn try_from(elem: Element) -> Result { - if !elem.is("c", ns::CAPS) { - return Err(Error::ParseError("This is not a caps element.")); - } - for _ in elem.children() { - return Err(Error::ParseError("Unknown child in caps element.")); - } - let hash = get_attr!(elem, "hash", required); + check_self!(elem, "c", ns::CAPS, "caps"); + check_no_children!(elem, "caps"); + check_no_unknown_attributes!(elem, "caps", ["hash", "ver", "ext", "node"]); let ver: String = get_attr!(elem, "ver", required); let hash = Hash { - algo: hash, + algo: get_attr!(elem, "hash", required), hash: base64::decode(&ver)?, }; Ok(Caps {