From 60ebcb8c8a425cb5f34a4f8c7afb40506d01983e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 14 Dec 2023 18:12:45 +0100 Subject: [PATCH] minidom: clippy pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- minidom/src/element.rs | 4 ++-- minidom/src/node.rs | 4 ++-- minidom/src/tree_builder.rs | 41 ++++++++++++++++++------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/minidom/src/element.rs b/minidom/src/element.rs index 6366fa2c..f1d1bba0 100644 --- a/minidom/src/element.rs +++ b/minidom/src/element.rs @@ -400,7 +400,7 @@ impl Element { )); } - let namespace = if self.namespace.len() == 0 { + let namespace = if self.namespace.is_empty() { None } else { Some(Arc::new(self.namespace.clone().try_into()?)) @@ -712,7 +712,7 @@ impl Element { /// Remove the leading nodes up to the first child element and /// return it pub fn unshift_child(&mut self) -> Option { - while self.children.len() > 0 { + while self.children.is_empty() { if let Some(el) = self.children.remove(0).into_element() { return Some(el); } diff --git a/minidom/src/node.rs b/minidom/src/node.rs index 1ea50632..b7f22316 100644 --- a/minidom/src/node.rs +++ b/minidom/src/node.rs @@ -201,8 +201,8 @@ impl From for Node { impl PartialEq for Node { fn eq(&self, other: &Self) -> bool { match (self, other) { - (&Node::Element(ref elem1), &Node::Element(ref elem2)) => elem1 == elem2, - (&Node::Text(ref text1), &Node::Text(ref text2)) => text1 == text2, + (Node::Element(elem1), Node::Element(elem2)) => elem1 == elem2, + (Node::Text(text1), Node::Text(text2)) => text1 == text2, _ => false, } } diff --git a/minidom/src/tree_builder.rs b/minidom/src/tree_builder.rs index 59df32e8..b991629c 100644 --- a/minidom/src/tree_builder.rs +++ b/minidom/src/tree_builder.rs @@ -18,6 +18,12 @@ pub struct TreeBuilder { pub root: Option, } +impl Default for TreeBuilder { + fn default() -> Self { + Self::new() + } +} + impl TreeBuilder { /// Create a new one pub fn new() -> Self { @@ -110,27 +116,20 @@ impl TreeBuilder { } RawEvent::Attribute(_, (prefix, name), value) => { - self.next_tag - .as_mut() - .map( - |(_, _, ref mut prefixes, ref mut attrs)| match (prefix, name) { - (None, xmlns) if xmlns == "xmlns" => { - prefixes.insert(None, value); - } - (Some(xmlns), prefix) if xmlns.as_str() == "xmlns" => { - prefixes.insert(Some(prefix.as_str().to_owned()), value); - } - (Some(prefix), name) => { - attrs.insert( - format!("{}:{}", prefix, name), - value.as_str().to_owned(), - ); - } - (None, name) => { - attrs.insert(name.as_str().to_owned(), value.as_str().to_owned()); - } - }, - ); + if let Some((_, _, ref mut prefixes, ref mut attrs)) = self.next_tag.as_mut() { + match (prefix, name) { + (None, xmlns) if xmlns == "xmlns" => prefixes.insert(None, value), + (Some(xmlns), prefix) if xmlns.as_str() == "xmlns" => { + prefixes.insert(Some(prefix.as_str().to_owned()), value); + } + (Some(prefix), name) => { + attrs.insert(format!("{}:{}", prefix, name), value.as_str().to_owned()); + } + (None, name) => { + attrs.insert(name.as_str().to_owned(), value.as_str().to_owned()); + } + } + } } RawEvent::ElementHeadClose(_) => {