Simplify string code, remove into

This commit is contained in:
andy.boot
2019-10-02 19:48:57 +01:00
parent c6f4ace2b6
commit fd35734a94
+7 -8
View File
@@ -35,14 +35,14 @@ fn get_size(nodes: &[(String, u64)], node_to_print: &str) -> Option<u64> {
None None
} }
fn display_node<S: Into<String>>( fn display_node(
node_to_print: &str, node_to_print: &str,
found: &mut HashSet<String>, found: &mut HashSet<String>,
to_display: &[(String, u64)], to_display: &[(String, u64)],
is_biggest: bool, is_biggest: bool,
short_paths: bool, short_paths: bool,
depth: Option<u64>, depth: Option<u64>,
indentation_str: S, indentation_str: &str,
) { ) {
if found.contains(node_to_print) { if found.contains(node_to_print) {
return; return;
@@ -57,9 +57,8 @@ fn display_node<S: Into<String>>(
match get_size(to_display, node_to_print) { match get_size(to_display, node_to_print) {
None => println!("Can not find path: {}", node_to_print), None => println!("Can not find path: {}", node_to_print),
Some(size) => { Some(size) => {
let is = indentation_str.into(); print_this_node(node_to_print, size, is_biggest, short_paths, indentation_str);
print_this_node(node_to_print, size, is_biggest, short_paths, is.as_ref()); let new_indent = clean_indentation_string(indentation_str);
let new_indent = clean_indentation_string(is);
let ntp_with_slash = strip_end_slash(node_to_print); let ntp_with_slash = strip_end_slash(node_to_print);
@@ -84,7 +83,7 @@ fn display_node<S: Into<String>>(
is_biggest, is_biggest,
short_paths, short_paths,
new_depth, new_depth,
new_indent.to_string() + get_tree_chars(num_siblings != 0, has_children), &*(new_indent.to_string() + get_tree_chars(num_siblings != 0, has_children)),
); );
is_biggest = false; is_biggest = false;
} }
@@ -93,8 +92,8 @@ fn display_node<S: Into<String>>(
} }
} }
fn clean_indentation_string<S: Into<String>>(s: S) -> String { fn clean_indentation_string(s: &str) -> String {
let mut is = s.into(); let mut is :String = s.into();
is = is.replace("└─┬", " "); is = is.replace("└─┬", " ");
is = is.replace("└──", " "); is = is.replace("└──", " ");
is = is.replace("├──", ""); is = is.replace("├──", "");