-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathconstructors.rs
More file actions
36 lines (32 loc) · 997 Bytes
/
constructors.rs
File metadata and controls
36 lines (32 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use super::DataTree;
use crate::size;
impl<Name, Size: size::Size> DataTree<Name, Size> {
/// Create a tree representation of a directory.
pub fn dir(name: Name, inode_size: Size, children: Vec<Self>) -> Self {
let size = inode_size + children.iter().map(DataTree::size).sum();
DataTree {
name,
size,
children,
}
}
/// Create a tree representation of a file.
pub fn file(name: Name, size: Size) -> Self {
DataTree {
name,
size,
children: Vec::new(),
}
}
/// Create a directory constructor of fixed inode size.
pub fn fixed_size_dir_constructor(inode_size: Size) -> impl Fn(Name, Vec<Self>) -> Self
where
Size: Copy,
{
move |name, children| DataTree::dir(name, inode_size, children)
}
/// Remove the children. Free memory usage.
pub(crate) fn drop_children(&mut self) {
self.children = Vec::new();
}
}