hashes, presence, message, iq, disco: Use get_attr!.
This commit is contained in:
parent
e7e4284a0d
commit
d61d09f5b7
5 changed files with 32 additions and 59 deletions
|
|
@ -169,16 +169,10 @@ impl<'a> TryFrom<&'a Element> for Message {
|
|||
if !root.is("message", ns::JABBER_CLIENT) {
|
||||
return Err(Error::ParseError("This is not a message element."));
|
||||
}
|
||||
let from = root.attr("from")
|
||||
.and_then(|value| value.parse().ok());
|
||||
let to = root.attr("to")
|
||||
.and_then(|value| value.parse().ok());
|
||||
let id = root.attr("id")
|
||||
.and_then(|value| value.parse().ok());
|
||||
let type_ = match root.attr("type") {
|
||||
Some(type_) => type_.parse()?,
|
||||
None => Default::default(),
|
||||
};
|
||||
let from = get_attr!(root, "from", optional);
|
||||
let to = get_attr!(root, "to", optional);
|
||||
let id = get_attr!(root, "id", optional);
|
||||
let type_ = get_attr!(root, "type", default);
|
||||
let mut bodies = BTreeMap::new();
|
||||
let mut subjects = BTreeMap::new();
|
||||
let mut thread = None;
|
||||
|
|
@ -188,7 +182,7 @@ impl<'a> TryFrom<&'a Element> for Message {
|
|||
for _ in elem.children() {
|
||||
return Err(Error::ParseError("Unknown child in body element."));
|
||||
}
|
||||
let lang = elem.attr("xml:lang").unwrap_or("").to_owned();
|
||||
let lang = get_attr!(root, "xml:lang", default);
|
||||
if bodies.insert(lang, elem.text()).is_some() {
|
||||
return Err(Error::ParseError("Body element present twice for the same xml:lang."));
|
||||
}
|
||||
|
|
@ -196,7 +190,7 @@ impl<'a> TryFrom<&'a Element> for Message {
|
|||
for _ in elem.children() {
|
||||
return Err(Error::ParseError("Unknown child in subject element."));
|
||||
}
|
||||
let lang = elem.attr("xml:lang").unwrap_or("").to_owned();
|
||||
let lang = get_attr!(root, "xml:lang", default);
|
||||
if subjects.insert(lang, elem.text()).is_some() {
|
||||
return Err(Error::ParseError("Subject element present twice for the same xml:lang."));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue