minidom: clippy pass

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-12-14 18:12:45 +01:00
parent 2b433d7036
commit 60ebcb8c8a
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2
3 changed files with 24 additions and 25 deletions

View file

@ -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<Element> {
while self.children.len() > 0 {
while self.children.is_empty() {
if let Some(el) = self.children.remove(0).into_element() {
return Some(el);
}

View file

@ -201,8 +201,8 @@ impl From<ElementBuilder> 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,
}
}

View file

@ -18,6 +18,12 @@ pub struct TreeBuilder {
pub root: Option<Element>,
}
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(_) => {