parallel_disk_usage/data_tree/
constructors.rs

1use super::DataTree;
2use crate::size;
3
4impl<Name, Size: size::Size> DataTree<Name, Size> {
5    /// Create a tree representation of a directory.
6    #[inline]
7    pub fn dir(name: Name, inode_size: Size, children: Vec<Self>) -> Self {
8        let size = inode_size + children.iter().map(DataTree::size).sum();
9        DataTree {
10            name,
11            size,
12            children,
13        }
14    }
15
16    /// Create a tree representation of a file.
17    #[inline]
18    pub fn file(name: Name, size: Size) -> Self {
19        DataTree {
20            name,
21            size,
22            children: Vec::new(),
23        }
24    }
25
26    /// Create a directory constructor of fixed inode size.
27    #[inline]
28    pub fn fixed_size_dir_constructor(inode_size: Size) -> impl Fn(Name, Vec<Self>) -> Self
29    where
30        Size: Copy,
31    {
32        move |name, children| DataTree::dir(name, inode_size, children)
33    }
34}