Skip to content

Commit

Permalink
refactor with clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
LoZack19 committed Aug 22, 2024
1 parent 45de3dd commit 129ad48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
23 changes: 13 additions & 10 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ struct Token {
children: bool,
}

impl ToString for Token {
fn to_string(&self) -> String {
impl Display for Token {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let Token { siblings, children } = self;

match (siblings, children) {
(true, true) => "│ ",
(true, false) => "├── ",
(false, true) => " ",
(false, false) => "└── ",
}
.to_string()
write!(
f,
"{}",
match (siblings, children) {
(true, true) => "│ ",
(true, false) => "├── ",
(false, true) => " ",
(false, false) => "└── ",
}
)
}
}

Expand Down Expand Up @@ -50,7 +53,7 @@ impl Display for Indentation {
let first: usize = if self.ignore_root { 1 } else { 0 };

for token in &self.tokens[first..] {
write!(f, "{}", token.to_string())?;
write!(f, "{token}")?;
}

Ok(())
Expand Down
9 changes: 2 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,16 +733,11 @@ impl<T: Display> Display for Tree<T> {
match edge {
Edge::Open(node) if node.has_children() => {
indent.indent(node.next_sibling().is_some());
write!(f, "{}{}\n", indent.to_string(), node.value())?;
}
Edge::Open(node) if node.next_sibling().is_some() => {
indent.indent(node.next_sibling().is_some());
write!(f, "{}{}\n", indent.to_string(), node.value())?;
indent.deindent();
writeln!(f, "{indent}{}", node.value())?;
}
Edge::Open(node) => {
indent.indent(node.next_sibling().is_some());
write!(f, "{}{}\n", indent.to_string(), node.value())?;
writeln!(f, "{indent}{}", node.value())?;
indent.deindent();
}
Edge::Close(node) if node.has_children() => {
Expand Down

0 comments on commit 129ad48

Please sign in to comment.