pub enum Node {
NonLeaf {
id: String,
children: Vec<Node>,
children_visible: bool,
},
Leaf(String),
}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.
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
impl Node
Sourcepub fn flatten_visibles(&self) -> Vec<Kind>
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 Kindrepresenting the visible nodes in the tree.
Sourcepub fn toggle(&mut self, path: &Path)
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.
Sourcepub fn get_waypoints(&self, path: &Path) -> Vec<String>
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.
Sourcepub fn get(&self, path: &Path) -> Option<&Node>
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.
Sourcepub fn get_mut(&mut self, path: &Path) -> Option<&mut Node>
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 TryFrom<&PathBuf> for Node
impl TryFrom<&PathBuf> for Node
Source§type Error = Error
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 aPathBufrepresenting the directory to be converted into aNode.
§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.
impl Eq for Node
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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