From f69f567448af99c71cb76bf5e80828468740674a Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 27 Aug 2017 01:04:56 +0100 Subject: [PATCH] =?UTF-8?q?Use=20minidom=C2=A00.6.1=E2=80=99s=20Element::h?= =?UTF-8?q?as=5Fns(),=20to=20simplify=20namespace=20comparisons.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chatstates.rs | 3 +-- src/jingle.rs | 3 +-- src/jingle_message.rs | 3 +-- src/stanza_error.rs | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/chatstates.rs b/src/chatstates.rs index 9a63a28..ecbecdf 100644 --- a/src/chatstates.rs +++ b/src/chatstates.rs @@ -38,8 +38,7 @@ impl TryFrom for ChatState { type Err = Error; fn try_from(elem: Element) -> Result { - let ns = elem.ns(); - if ns.as_ref().map(|ns| ns.as_str()) != Some(ns::CHATSTATES) { + if !elem.has_ns(ns::CHATSTATES) { return Err(Error::ParseError("This is not a chatstate element.")); } for _ in elem.children() { diff --git a/src/jingle.rs b/src/jingle.rs index d20ed05..9d14261 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -208,8 +208,7 @@ impl TryFrom for ReasonElement { let mut reason = None; let mut text = None; for child in elem.children() { - let child_ns = child.ns(); - if child_ns.as_ref().map(|ns| ns.as_str()) != Some(ns::JINGLE) { + if !child.has_ns(ns::JINGLE) { return Err(Error::ParseError("Reason contains a foreign element.")); } match child.name() { diff --git a/src/jingle_message.rs b/src/jingle_message.rs index 57cebe8..779af99 100644 --- a/src/jingle_message.rs +++ b/src/jingle_message.rs @@ -47,8 +47,7 @@ impl TryFrom for JingleMI { type Err = Error; fn try_from(elem: Element) -> Result { - let ns = elem.ns(); - if ns.as_ref().map(|ns| ns.as_str()) != Some(ns::JINGLE_MESSAGE) { + if !elem.has_ns(ns::JINGLE_MESSAGE) { return Err(Error::ParseError("This is not a Jingle message element.")); } Ok(match elem.name() { diff --git a/src/stanza_error.rs b/src/stanza_error.rs index 1ed542c..bbc3162 100644 --- a/src/stanza_error.rs +++ b/src/stanza_error.rs @@ -136,7 +136,6 @@ impl TryFrom for StanzaError { let mut other = None; for child in elem.children() { - let child_ns = child.ns(); if child.is("text", ns::XMPP_STANZAS) { for _ in child.children() { return Err(Error::ParseError("Unknown element in error text.")); @@ -145,7 +144,7 @@ impl TryFrom for StanzaError { if texts.insert(lang, child.text()).is_some() { return Err(Error::ParseError("Text element present twice for the same xml:lang.")); } - } else if child_ns.as_ref().map(|ns| ns.as_str()) == Some(ns::XMPP_STANZAS) { + } else if child.has_ns(ns::XMPP_STANZAS) { if defined_condition.is_some() { return Err(Error::ParseError("Error must not have more than one defined-condition.")); }