Skip to main content

Node

Enum Node 

Source
pub enum Node {
    NonLeaf {
        id: String,
        children: Vec<Node>,
        children_visible: bool,
    },
    Leaf(String),
}
Available on crate feature tree only.
Expand description

Represents a node within a tree structure.

A node can either be a NonLeaf, containing children and a visibility flag, or a Leaf, representing an end node without children.

Variants§

§

NonLeaf

Represents a non-leaf node, which can contain child nodes.

  • id: A unique identifier for the node.
  • children: A vector of child nodes.
  • children_visible: A boolean indicating if the children of this node are visible.

Fields

§children: Vec<Node>
§children_visible: bool
§

Leaf(String)

Represents a leaf node, which does not contain any child nodes.

  • id: A unique identifier for the leaf node.

Implementations§

Source§

impl Node

Source

pub fn flatten_visibles(&self) -> Vec<Kind>

Flattens the tree structure into a vector of Kind, including only visible nodes.

This method performs a depth-first search (DFS) to traverse the tree and collect nodes into a vector. Each node is represented as either Kind::Folded or Kind::Unfolded based on its visibility and whether it has children.

Returns:

  • Vec: A vector of Kind representing the visible nodes in the tree.
Source

pub fn toggle(&mut self, path: &Path)

Toggles the visibility of the children of the node specified by the given path.

Parameters:

  • path: &Path - A reference to a vector of usize, representing the path to the target node.

This method modifies the tree in-place. If the target node is found and is a NonLeaf, its children_visible field is toggled.

Source

pub fn get_waypoints(&self, path: &Path) -> Vec<String>

Retrieves the IDs of all nodes along the path to a specified node.

Parameters:

  • path: &Path - A reference to a vector of usize, representing the path to the target node.

Returns:

  • Vec: A vector of String IDs representing the nodes along the path to the target node.
Source

pub fn get(&self, path: &Path) -> Option<&Node>

Retrieves a reference to the node specified by the given path.

Parameters:

  • path: &Path - A reference to a vector of usize, representing the path to the target node.

Returns:

  • Option<&Node>: An option containing a reference to the target node if found, or None otherwise.
Source

pub fn get_mut(&mut self, path: &Path) -> Option<&mut Node>

Retrieves a mutable reference to the node specified by the given path.

Parameters:

  • path: &Path - A reference to a vector of usize, representing the path to the target node.

Returns:

  • Option<&mut Node>: An option containing a mutable reference to the target node if found, or None otherwise.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

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

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

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&PathBuf> for Node

Source§

type Error = Error

Attempts to create a Node from a given directory path.

This method constructs a Node::NonLeaf representing the directory specified by dir_path. It recursively explores the directory, converting subdirectories into Node::NonLeaf instances and files into Node::Leaf instances. Directories and files are kept in separate lists initially, then combined with all directories first, followed by files. Both lists are sorted alphabetically before merging. The resulting tree structure reflects the hierarchy of files and directories within dir_path, with directories listed before files, both in alphabetical order.

§Parameters
  • dir_path: A reference to a PathBuf representing the directory to be converted into a Node.
§Returns

A Result containing the root Node of the constructed tree if successful, or an Error if the directory cannot be read or if any file name cannot be converted to a string.

§Errors

This method returns an Error if:

  • The path does not exist or is not a directory.
  • There is an error reading the directory contents.
  • A file name cannot be converted to a UTF-8 string.
Source§

fn try_from(dir_path: &PathBuf) -> Result<Self>

Performs the conversion.
Source§

impl Eq for Node

Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.