Enum TreeBuilder

Source
pub enum TreeBuilder {
    Directory(HashMap<String, TreeBuilder>),
    Leaf(Arc<dyn DirectoryEntry>),
}

Variants§

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.

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).

Source

pub fn empty_dir() -> Self

Constructs an empty builder. It is always an empty crate::directory::immutable::Simple directory.

Source

pub fn add_entry<'components, P, PathImpl>( &mut self, path: P, entry: Arc<dyn DirectoryEntry>, ) -> Result<(), Error>
where P: Into<Path<'components, PathImpl>> + 'components, PathImpl: AsRef<[&'components str]>,

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.

Source

pub fn add_empty_dir<'components, P, PathImpl>( &mut self, path: P, ) -> Result<(), Error>
where P: Into<Path<'components, PathImpl>> + 'components, PathImpl: AsRef<[&'components str]>,

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"));
Source

pub fn build(self) -> Arc<Simple>

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoAny for T
where T: 'static + Send + Sync,

Source§

fn into_any(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Cast the given object into a dyn std::any::Any.
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V