pub enum TreeBuilder {
Directory(HashMap<String, TreeBuilder>),
Leaf(Arc<dyn DirectoryEntry>),
}
Variants§
Directory(HashMap<String, TreeBuilder>)
Leaf(Arc<dyn DirectoryEntry>)
Implementations§
Source§impl TreeBuilder
Collects a number of DirectoryEntry
nodes and corresponding paths and the constructs a tree
of crate::directory::immutable::simple::Simple
directories that hold these nodes. This is a
companion tool, related to the vfs_macros::pseudo_directory!
macro, except that it is
collecting the paths dynamically, while the vfs_macros::pseudo_directory!
expects the tree
to be specified at compilation time.
impl TreeBuilder
Collects a number of DirectoryEntry
nodes and corresponding paths and the constructs a tree
of crate::directory::immutable::simple::Simple
directories that hold these nodes. This is a
companion tool, related to the vfs_macros::pseudo_directory!
macro, except that it is
collecting the paths dynamically, while the vfs_macros::pseudo_directory!
expects the tree
to be specified at compilation time.
Note that the final tree is build as a result of the Self::build()
method that consumes the
builder. You would need to use the crate::directory::helper::DirectlyMutable::add_entry()
interface to add any new nodes afterwards (a crate::directory::watchers::Controller
APIs).
Sourcepub fn empty_dir() -> Self
pub fn empty_dir() -> Self
Constructs an empty builder. It is always an empty crate::directory::immutable::Simple
directory.
Sourcepub fn add_entry<'components, P, PathImpl>(
&mut self,
path: P,
entry: Arc<dyn DirectoryEntry>,
) -> Result<(), Error>
pub fn add_entry<'components, P, PathImpl>( &mut self, path: P, entry: Arc<dyn DirectoryEntry>, ) -> Result<(), Error>
Adds a DirectoryEntry
at the specified path. It can be either a file or a directory.
In case it is a directory, this builder cannot add new child nodes inside of the added
directory. Any entry
is treated as an opaque “leaf” as far as the builder is concerned.
Sourcepub fn add_empty_dir<'components, P, PathImpl>(
&mut self,
path: P,
) -> Result<(), Error>
pub fn add_empty_dir<'components, P, PathImpl>( &mut self, path: P, ) -> Result<(), Error>
Adds an empty directory into the generated tree at the specified path. The difference with
the crate::directory::helper::DirectlyMutable::add_entry
that adds an entry that is a directory is that the builder can can only
add leaf nodes. In other words, code like this will fail:
use crate::{
directory::immutable::Simple,
file::vmo::read_only,
};
let mut tree = TreeBuilder::empty_dir();
tree.add_entry(&["dir1"], Simple::new());
tree.add_entry(&["dir1", "nested"], read_only(b"A file"));
The problem is that the builder does not see “dir1” as a directory, but as a leaf node that it cannot descend into.
If you use add_empty_dir()
instead, it would work:
use crate::file::vmo::read_only;
let mut tree = TreeBuilder::empty_dir();
tree.add_empty_dir(&["dir1"]);
tree.add_entry(&["dir1", "nested"], read_only(b"A file"));
pub fn build(self) -> Arc<Simple>
Sourcepub fn build_with_inode_generator(
self,
get_inode: &mut impl FnMut(String) -> u64,
) -> Arc<Simple>
pub fn build_with_inode_generator( self, get_inode: &mut impl FnMut(String) -> u64, ) -> Arc<Simple>
Consumes the builder, producing a tree with all the nodes provided to
crate::directory::helper::DirectlyMutable::add_entry()
at their respective locations.
The tree itself is built using crate::directory::immutable::Simple
nodes, and the top level is a directory.
Auto Trait Implementations§
impl Freeze for TreeBuilder
impl !RefUnwindSafe for TreeBuilder
impl Send for TreeBuilder
impl Sync for TreeBuilder
impl Unpin for TreeBuilder
impl !UnwindSafe for TreeBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more