delay, eme, stanza_error: Use get_attr!.

This commit is contained in:
Emmanuel Gil Peyrot 2017-05-23 01:02:23 +01:00
commit e3f1f31718
4 changed files with 11 additions and 17 deletions

View file

@ -30,8 +30,8 @@ impl<'a> TryFrom<&'a Element> for Delay {
for _ in elem.children() {
return Err(Error::ParseError("Unknown child in delay element."));
}
let from = elem.attr("from").and_then(|value| value.parse().ok());
let stamp = elem.attr("stamp").ok_or(Error::ParseError("Mandatory argument 'stamp' not present in delay element."))?.to_owned();
let from = get_attr!(elem, "from", optional);
let stamp = get_attr!(elem, "stamp", required);
let data = match elem.text().as_ref() {
"" => None,
text => Some(text.to_owned()),