caps: Use the new helper macros to simplify parsing.
This commit is contained in:
parent
66fb8fea74
commit
a2b6033336
1 changed files with 4 additions and 8 deletions
12
src/caps.rs
12
src/caps.rs
|
@ -33,16 +33,12 @@ impl TryFrom<Element> for Caps {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Caps, Error> {
|
fn try_from(elem: Element) -> Result<Caps, Error> {
|
||||||
if !elem.is("c", ns::CAPS) {
|
check_self!(elem, "c", ns::CAPS, "caps");
|
||||||
return Err(Error::ParseError("This is not a caps element."));
|
check_no_children!(elem, "caps");
|
||||||
}
|
check_no_unknown_attributes!(elem, "caps", ["hash", "ver", "ext", "node"]);
|
||||||
for _ in elem.children() {
|
|
||||||
return Err(Error::ParseError("Unknown child in caps element."));
|
|
||||||
}
|
|
||||||
let hash = get_attr!(elem, "hash", required);
|
|
||||||
let ver: String = get_attr!(elem, "ver", required);
|
let ver: String = get_attr!(elem, "ver", required);
|
||||||
let hash = Hash {
|
let hash = Hash {
|
||||||
algo: hash,
|
algo: get_attr!(elem, "hash", required),
|
||||||
hash: base64::decode(&ver)?,
|
hash: base64::decode(&ver)?,
|
||||||
};
|
};
|
||||||
Ok(Caps {
|
Ok(Caps {
|
||||||
|
|
Loading…
Reference in a new issue