diff --git a/minidom/src/element.rs b/minidom/src/element.rs index 6366fa2..f1d1bba 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 1ea5063..b7f2231 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 59df32e..b991629 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(_) => {