pub struct FileTree { /* private fields */ }Expand description
FileTree is a specialized data structure for compactly storing in memory hierarchical
structure of files and directories. It also provides fast search and access to data.
Implementation Features
If all the file paths you plan to store in FileTree begin with the same long prefix,
it’s better to store this prefix separately, outside of this structure.
For example, you have several file paths:
/very/long/prefix/to/my/files/file.01
/very/long/prefix/to/my/files/alfa/file.02
/very/long/prefix/to/my/files/beta/gamma/file.03Common prefix is: /very/long/prefix/to/my/files - store it separately.
And in FileTree store short paths: /file.01, /alfa/file.02 and /beta/gamma/file.03.
In this case, FileTree will store the following hierarchy:
/
+-------------+--------------+
file.01 alfa beta
/ /
file.02 gamma
/
file.03All paths in FileTree must be absolute (i.e., start with /).
Do not include any prefixes into paths (for example, like in Windows - C:).
Implementations§
Source§impl FileTree
impl FileTree
Sourcepub fn contains_file<P: AsRef<Path>>(&self, path: P) -> Result<bool>
pub fn contains_file<P: AsRef<Path>>(&self, path: P) -> Result<bool>
Checks if path is contained in the tree as file.
Efficiency: O(n), where n is a path length (in components).
Sourcepub fn contains_dir<P: AsRef<Path>>(&self, path: P) -> Result<bool>
pub fn contains_dir<P: AsRef<Path>>(&self, path: P) -> Result<bool>
Checks if path is contained in the tree as directory.
Efficiency: O(n), where n is a path length (in components).
Sourcepub fn add_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn add_dir<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Add directory into tree.
path must be absolute (i.e., start with /) and not contain prefixes
(for example, like in Windows - C:).
Efficiency: O(n), where n is a path length (in components).
Sourcepub fn add_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn add_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Add file into tree.
path must be absolute (i.e., start with /) and not contain prefixes
(for example, like in Windows - C:).
Efficiency: O(n), where n is a path length (in components).
Sourcepub fn remove_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
pub fn remove_file<P: AsRef<Path>>(&mut self, path: P) -> Result<()>
Removes a file from the tree.