* remove unneeded identity .map()

* remove redunant field name in struct

* impl num_siblings for Node

* replace nested if w/ match in get_tree_chars

* remove unneeded field name in struct

* remove redundant println! & logic in display_node

* make get_children_from_node a Node method

* Revert "remove redundant println! & logic in display_node"

This reverts commit 40777025d5.
This commit is contained in:
Tyler Bailey
2020-10-21 16:01:18 -05:00
committed by GitHub
parent ca8b1efc18
commit 9d13994526
2 changed files with 34 additions and 39 deletions
+17 -1
View File
@@ -17,7 +17,7 @@ use self::platform::*;
type PathData = (PathBuf, u64, Option<(u64, u64)>);
#[derive(Debug, Default, Eq)]
#[derive(Debug, Default, Eq, Clone)]
pub struct Node {
pub name: PathBuf,
pub size: u64,
@@ -46,6 +46,22 @@ impl PartialEq for Node {
}
}
impl Node {
pub fn num_siblings(&self) -> u64 {
self.children.len() as u64
}
pub fn get_children_from_node(&self, is_reversed: bool) -> impl Iterator<Item = Node> {
let children = self.children.clone();
if is_reversed {
let children: Vec<Node> = children.into_iter().rev().collect();
return children.into_iter();
}
children.into_iter()
}
}
pub fn is_a_parent_of<P: AsRef<Path>>(parent: P, child: P) -> bool {
let parent = parent.as_ref();
let child = child.as_ref();