From b4c6c68527631e2176a8665fc24203a3b732767c Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 20 Mar 2018 19:10:24 -0700 Subject: [PATCH 1/4] minor whitespace changes from rustfmt --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index fc48580..47f557c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,7 +253,7 @@ fn find_big_ones<'a>(l: &'a Vec, max_to_show: usize) -> Vec<&Node> { } } -fn display(permissions: bool, to_display: Vec<&Node>) -> () { +fn display(permissions: bool, to_display: &Vec<&Node>) -> () { if !permissions { eprintln!("Did not have permissions for all directories"); } From f802d7a6b4c6f066ab9b2a5bdd96c83eb5a20a0b Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 20 Mar 2018 19:15:42 -0700 Subject: [PATCH 2/4] quiet some clippy warnings --- src/main.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 47f557c..5d4492a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,8 +31,8 @@ impl Ord for Node { } else if self.dir.size < other.dir.size { Ordering::Greater } else { - let my_slashes = self.dir.name.matches("/").count(); - let other_slashes = other.dir.name.matches("/").count(); + let my_slashes = self.dir.name.matches('/').count(); + let other_slashes = other.dir.name.matches('/').count(); if my_slashes > other_slashes { Ordering::Greater @@ -68,7 +68,7 @@ struct Dir { size: u64, } -static DEFAULT_NUMBER_OF_LINES: &'static str = &"15"; +static DEFAULT_NUMBER_OF_LINES: &'static str = "15"; fn main() { let options = App::new("Trailing args example") @@ -91,16 +91,16 @@ fn main() { }; let number_of_lines = value_t!(options.value_of("number_of_lines"), usize).unwrap(); - let (permissions, results) = get_dir_tree(filenames); + let (permissions, results) = get_dir_tree(&filenames); let slice_it = find_big_ones(&results, number_of_lines); - display(permissions, slice_it); + display(permissions, &slice_it); } -fn get_dir_tree(filenames: Vec<&str>) -> (bool, Vec) { +fn get_dir_tree(filenames: &Vec<&str>) -> (bool, Vec) { let mut permissions = true; let mut results = vec![]; for b in filenames { - let mut new_name = String::from(b); + let mut new_name = String::from(*b); while new_name.chars().last() == Some('/') && new_name.len() != 1 { new_name.pop(); } @@ -274,11 +274,11 @@ fn display_node>( is = is.replace("└──", " "); is = is.replace("├──", "│ "); - let printable_node_slashes = node_to_print.dir.name.matches("/").count(); + let printable_node_slashes = node_to_print.dir.name.matches('/').count(); let mut num_sibblings = to_display.iter().fold(0, |a, b| { if node_to_print.children.contains(b) - && b.dir.name.matches("/").count() == printable_node_slashes + 1 + && b.dir.name.matches('/').count() == printable_node_slashes + 1 { a + 1 } else { @@ -346,6 +346,7 @@ fn human_readable_number(size: u64) -> (String) { } mod tests { + #[allow(unused_imports)] use super::*; #[test] From 1c80cbf28bbcfe0b33c1abc999719dbf9b6329c1 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 20 Mar 2018 19:23:21 -0700 Subject: [PATCH 3/4] Make printing slightly prettier --- src/main.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5d4492a..72d3d97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -271,8 +271,10 @@ fn display_node>( let mut is = indentation_str.into(); print_this_node(node_to_print, is_first, depth, is.as_ref()); - is = is.replace("└──", " "); - is = is.replace("├──", "│ "); + is = is.replace("└─┬", " "); + is = is.replace("└──", " "); + is = is.replace("├──", "│ "); + is = is.replace("├─┬", "│ "); let printable_node_slashes = node_to_print.dir.name.matches('/').count(); @@ -287,15 +289,29 @@ fn display_node>( }); let mut is_biggest = true; + let mut has_display_children = false; for node in to_display { if node_to_print.children.contains(node) { + let has_children = node.children.len() > 0; if node.dir.name.matches("/").count() == printable_node_slashes + 1 { num_sibblings -= 1; + for ref n in node.children.iter() { + has_display_children = has_display_children || to_display.contains(n); + } + let has_children = has_children && has_display_children; let tree_chars = { if num_sibblings == 0 { - "└──" + if has_children { + "└─┬" + } else { + "└──" + } } else { - "├──" + if has_children { + "├─┬" + } else { + "├──" + } } }; display_node( From 99f462f0231dd88e1195f157544fa2bcc51d52a4 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 20 Mar 2018 20:40:36 -0700 Subject: [PATCH 4/4] s/sibblings/siblings/g --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 72d3d97..4630eac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -278,7 +278,7 @@ fn display_node>( let printable_node_slashes = node_to_print.dir.name.matches('/').count(); - let mut num_sibblings = to_display.iter().fold(0, |a, b| { + let mut num_siblings = to_display.iter().fold(0, |a, b| { if node_to_print.children.contains(b) && b.dir.name.matches('/').count() == printable_node_slashes + 1 { @@ -294,13 +294,13 @@ fn display_node>( if node_to_print.children.contains(node) { let has_children = node.children.len() > 0; if node.dir.name.matches("/").count() == printable_node_slashes + 1 { - num_sibblings -= 1; + num_siblings -= 1; for ref n in node.children.iter() { has_display_children = has_display_children || to_display.contains(n); } let has_children = has_children && has_display_children; let tree_chars = { - if num_sibblings == 0 { + if num_siblings == 0 { if has_children { "└─┬" } else {