Calculate bad children on-the-fly.
This commit is contained in:
parent
52b401d548
commit
52df376553
@ -11,10 +11,9 @@ pub struct DiffResult {
|
|||||||
children: Vec<DiffResult>,
|
children: Vec<DiffResult>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum DiffStatus {
|
pub enum DiffStatus {
|
||||||
Good,
|
Good,
|
||||||
ChildBad,
|
|
||||||
Bad,
|
Bad,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,10 +23,22 @@ impl DiffResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn print_indented(&self, indentation: usize) -> Result<(), Box<dyn std::error::Error>> {
|
fn print_indented(&self, indentation: usize) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let status_text = {
|
||||||
|
match self.status {
|
||||||
|
DiffStatus::Good => {
|
||||||
|
if self.has_bad_children() {
|
||||||
|
"BADCHILD"
|
||||||
|
} else {
|
||||||
|
"GOOD"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DiffStatus::Bad => "BAD",
|
||||||
|
}
|
||||||
|
};
|
||||||
println!(
|
println!(
|
||||||
"{}{:?} {}",
|
"{}{} {}",
|
||||||
" ".repeat(indentation),
|
" ".repeat(indentation),
|
||||||
self.status,
|
status_text,
|
||||||
self.name
|
self.name
|
||||||
);
|
);
|
||||||
for child in self.children.iter() {
|
for child in self.children.iter() {
|
||||||
@ -35,6 +46,10 @@ impl DiffResult {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_bad_children(&self) -> bool {
|
||||||
|
self.children.iter().any(|child| {child.status == DiffStatus::Bad || child.has_bad_children()})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compare_document<'s>(
|
pub fn compare_document<'s>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user