summaryrefslogtreecommitdiffstats
path: root/src/tree.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-28 18:39:23 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-28 18:39:23 +0100
commit7d2ad7ece9036445225423a3a4a0632a9ea55f01 (patch)
tree1554bd646eda75819bf1178a5f88095a30bd3aed /src/tree.rs
parent9a8ac63bda81af752ce7f3a24b3851491189b05e (diff)
refactor tree
Diffstat (limited to 'src/tree.rs')
-rw-r--r--src/tree.rs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/tree.rs b/src/tree.rs
index d38594b..957720e 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -90,6 +90,16 @@ impl Node {
pub fn toggle_fold(&mut self) {
self.folded = !self.folded;
}
+
+ fn from_fileinfo(fileinfo: FileInfo, parent_position: Vec<usize>) -> Self {
+ Self {
+ is_dir: matches!(fileinfo.file_kind, FileKind::Directory),
+ fileinfo,
+ position: parent_position,
+ folded: false,
+ index: None,
+ }
+ }
}
/// Holds a recursive view of a directory.
@@ -135,6 +145,13 @@ impl Tree {
)
}
+ /// Clear every vector attributes of the tree.
+ /// It's used to free some unused memory.
+ pub fn clear(&mut self) {
+ self.leaves = vec![];
+ self.position = vec![];
+ }
+
/// A reference to the holded node fileinfo.
pub fn file(&self) -> &FileInfo {
&self.node.fileinfo
@@ -172,13 +189,7 @@ impl Tree {
}
}
}
- let node = Node {
- is_dir: matches!(fileinfo.file_kind, FileKind::Directory),
- fileinfo,
- position: parent_position,
- folded: false,
- index: None,
- };
+ let node = Node::from_fileinfo(fileinfo, parent_position);
let position = vec![0];
let current_node = node.clone();
Ok(Self {