Skip to content

Commit 194446a

Browse files
committed
cargo clippy
1 parent afaaae3 commit 194446a

5 files changed

Lines changed: 14 additions & 21 deletions

File tree

examples/get_all_href/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use html_parser::{Dom, Node, Result};
55
fn main() -> Result<()> {
66
let html = include_str!("./index.html");
77
let dom = Dom::parse(html)?;
8-
let iter = dom.children.get(0).unwrap().into_iter();
8+
let iter = dom.children.first().unwrap().into_iter();
99

1010
let hrefs = iter.filter_map(|item| match item {
1111
Node::Element(element) if element.name == "a" => element.attributes["href"].clone(),

src/dom/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,13 @@ impl Dom {
177177
if dom
178178
.children
179179
.iter()
180-
.filter(|x| match x {
181-
Node::Element(el) if el.name.to_lowercase() == "html" => true,
182-
_ => false,
183-
})
180+
.filter(|x| matches!(x, Node::Element(el) if el.name.to_lowercase() == "html"))
184181
.count()
185182
> 1
186183
{
187-
return Err(Error::Parsing(format!("Document with multiple HTML tags",)));
184+
return Err(Error::Parsing(
185+
"Document with multiple HTML tags".to_string(),
186+
));
188187
}
189188
}
190189

@@ -318,7 +317,7 @@ impl Dom {
318317
}
319318
}
320319
}
321-
if element.name != "" {
320+
if !element.name.is_empty() {
322321
Ok(Some(Node::Element(element)))
323322
} else {
324323
Ok(None)
@@ -336,11 +335,7 @@ impl Dom {
336335
attribute.1 = Some(pair.as_str().trim().to_string());
337336
}
338337
Rule::attr_quoted => {
339-
let inner_pair = pair
340-
.into_inner()
341-
.into_iter()
342-
.next()
343-
.expect("attribute value");
338+
let inner_pair = pair.into_inner().next().expect("attribute value");
344339

345340
match inner_pair.as_rule() {
346341
Rule::attr_value => attribute.1 = Some(inner_pair.as_str().to_string()),

src/dom/node.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ impl<'a> Iterator for NodeIntoIterator<'a> {
5656
fn next(&mut self) -> Option<Self::Item> {
5757
// Get first child
5858
let child = match self.node {
59-
Node::Element(e) => e.children.get(0),
59+
Node::Element(e) => e.children.first(),
6060
_ => None,
6161
};
6262

63-
let result = match child {
63+
match child {
6464
// If element has child, return child
6565
Some(child) => {
6666
self.index.push((0, self.node));
6767
self.node = child;
6868
Some(child)
6969
}
7070
// If element doesn't have a child, but is a child of another node
71-
None if self.index.len() > 0 => {
71+
None if !self.index.is_empty() => {
7272
let mut has_finished = false;
7373
let mut next_node = None;
7474

@@ -101,9 +101,7 @@ impl<'a> Iterator for NodeIntoIterator<'a> {
101101
next_node
102102
}
103103
_ => None,
104-
};
105-
106-
result
104+
}
107105
}
108106
}
109107

tests/node_iter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ fn it_can_iter_1() -> Result<()> {
1717
</body>
1818
</html>
1919
"};
20-
let dom = Dom::parse(&html)?;
21-
let root = dom.children.get(0).unwrap().into_iter();
20+
let dom = Dom::parse(html)?;
21+
let root = dom.children.first().unwrap().into_iter();
2222
let num_li = root.into_iter().fold(0, |mut acc, curr| match curr {
2323
Node::Element(e) => {
2424
if e.name == "li" {

tests/svg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ fn it_can_parse_complex_svg() {
4141
</svg>
4242
"#
4343
);
44-
assert!(Dom::parse(&svg).is_ok());
44+
assert!(Dom::parse(svg).is_ok());
4545
}

0 commit comments

Comments
 (0)