From 8c53d6e415fe420aef4375eef765ceb56774329a Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 21 May 2017 20:56:04 +0100 Subject: [PATCH] stanza_id: Use the new get_attr! macro to get attributes. --- src/stanza_id.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/stanza_id.rs b/src/stanza_id.rs index d478b1aa..2b87890b 100644 --- a/src/stanza_id.rs +++ b/src/stanza_id.rs @@ -35,15 +35,9 @@ impl<'a> TryFrom<&'a Element> for StanzaId { for _ in elem.children() { return Err(Error::ParseError("Unknown child in stanza-id or origin-id element.")); } - let id = match elem.attr("id") { - Some(id) => id.to_owned(), - None => return Err(Error::ParseError("No 'id' attribute present in stanza-id or origin-id.")), - }; + let id = get_attr!(elem, "id", required); Ok(if is_stanza_id { - let by = match elem.attr("by") { - Some(by) => by.parse().unwrap(), - None => return Err(Error::ParseError("No 'by' attribute present in stanza-id.")), - }; + let by = get_attr!(elem, "by", required); StanzaId::StanzaId { id, by } } else { StanzaId::OriginId { id } @@ -115,7 +109,7 @@ mod tests { Error::ParseError(string) => string, _ => panic!(), }; - assert_eq!(message, "No 'id' attribute present in stanza-id or origin-id."); + assert_eq!(message, "Required attribute 'id' missing."); } #[test] @@ -126,7 +120,7 @@ mod tests { Error::ParseError(string) => string, _ => panic!(), }; - assert_eq!(message, "No 'by' attribute present in stanza-id."); + assert_eq!(message, "Required attribute 'by' missing."); } #[test]