Skip to main content

TreeBuilder

Struct TreeBuilder 

Source
pub struct TreeBuilder { /* private fields */ }
Expand description

An in-memory, programmatic source: add entries, then hand it to the model.

Order of addition does not affect the result — the model sorts by path so the inode numbering is deterministic — but a directory’s contents are only valid if the directory itself is also added.

Implementations§

Source§

impl TreeBuilder

Source

pub fn new() -> Self

A builder with no entries. The root directory always exists implicitly and is not added here.

Source

pub fn directory(self, path: impl Into<Vec<u8>>, meta: Metadata) -> Self

Add a directory at path.

Source

pub fn root(self, meta: Metadata) -> Self

Set the root directory’s own metadata, overriding the 0755 root-owned default.

The root already exists, so this describes it rather than adding an entry; any xattr that follows attaches to the root. Naming it once is enough — a second root entry is a duplicate the model rejects.

Source

pub fn file( self, path: impl Into<Vec<u8>>, contents: impl Into<FileContent>, meta: Metadata, ) -> Self

Add a regular file at path with contents.

contents is anything that converts into a FileContent: an owned Vec<u8> or String, a borrowed &[u8], &[u8; N], or &str — each copied into the entry — or a FileRange, which names bytes on the host and reads them when the file is placed rather than now.

Add a symbolic link at path pointing at target.

Add a hard link at path to the entry already declared at target, which may be of any kind but a directory, and may itself be a hard link.

The link shares the target’s inode, so the two names are one file: the metadata, extended attributes, and contents are the inode’s, and the meta given here is not applied.

Source

pub fn char_device( self, path: impl Into<Vec<u8>>, major: u32, minor: u32, meta: Metadata, ) -> Self

Add a character-special device node at path.

Source

pub fn block_device( self, path: impl Into<Vec<u8>>, major: u32, minor: u32, meta: Metadata, ) -> Self

Add a block-special device node at path.

Source

pub fn fifo(self, path: impl Into<Vec<u8>>, meta: Metadata) -> Self

Add a named pipe (FIFO) at path.

Source

pub fn socket(self, path: impl Into<Vec<u8>>, meta: Metadata) -> Self

Add a Unix-domain socket node at path.

Source

pub fn xattr(self, name: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self

Attach an extended attribute to the most recently added entry.

name is the fully-qualified attribute name (e.g. b"security.capability"). If no entry has been added yet, the call has no effect.

Trait Implementations§

Source§

impl Clone for TreeBuilder

Source§

fn clone(&self) -> TreeBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TreeBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TreeBuilder

Source§

fn default() -> TreeBuilder

Returns the “default value” for a type. Read more
Source§

impl Source for TreeBuilder

Source§

fn into_entries(self) -> Vec<SourceEntry>

Produce the entries, consuming the source.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.