Skip to main content

FileTree

Struct FileTree 

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

In-memory file tree tracking directory structure during formatting.

Implementations§

Source§

impl FileTree

Source

pub fn new(root_inode: InodeNumber, name: &str) -> Self

Create a new file tree with a single root node.

Source

pub fn root(&self) -> usize

Return the index of the root node.

Source

pub fn node(&self, idx: usize) -> &FileTreeNode

Borrow a node by index.

Source

pub fn node_mut(&mut self, idx: usize) -> &mut FileTreeNode

Mutably borrow a node by index.

Source

pub fn lookup(&self, path: &Path) -> Option<usize>

Look up a node by path, walking the tree from the root.

The path is split into components. A leading “/” or empty first component is skipped so that both “/foo/bar” and “foo/bar” resolve identically. Returns None if any component is not found.

Source

pub fn add_child(&mut self, parent: usize, node: FileTreeNode) -> usize

Add a child node under parent, returning the new node’s index.

Source

pub fn remove_child(&mut self, parent: usize, name: &str)

Remove the first child with the given name from parent’s children list.

The node itself remains in the vector (indices are stable), but the parent no longer references it.

Source

pub fn node_path(&self, idx: usize) -> PathBuf

Reconstruct the full path of a node by walking the parent chain.

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