pub struct Node<T> {
pub value: T,
pub children: Vec<Node<T>>,
}Expand description
A generic tree node implementation.
This struct provides a simple implementation of a tree node with a value and a vector of children.
It implements both TreeNode and TreeNodeMut traits, allowing it to be used with both
immutable and mutable iterators.
§Type Parameters
T- The type of value stored in each node.
§Examples
use tree_iter::tree::Node;
use tree_iter::prelude::*;
// Create a simple tree
let tree = Node {
value: 1,
children: vec![Node::new(2), Node::new(3)],
};
// Traverse in depth-first order
let values: Vec<i32> = tree.iter::<DepthFirst>()
.map(|node| node.value)
.collect();
assert_eq!(values, vec![1, 2, 3]);Fields§
§value: TThe value stored in this node.
children: Vec<Node<T>>The children of this node.
Implementations§
Trait Implementations§
Source§impl<T> TreeNode for Node<T>
Implementation of TreeNode for Node<T>.
impl<T> TreeNode for Node<T>
Implementation of TreeNode for Node<T>.
This allows immutable iteration over the tree.
Source§impl<T> TreeNodeMut for Node<T>
Implementation of TreeNodeMut for Node<T>.
impl<T> TreeNodeMut for Node<T>
Implementation of TreeNodeMut for Node<T>.
This allows mutable iteration over the tree.
Source§fn children_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Self>
fn children_mut(&mut self) -> impl DoubleEndedIterator<Item = &mut Self>
Returns a mutable iterator over the children of this node.
Source§fn iter_mut<T: TraversalOrder>(&mut self) -> TreeIterMut<'_, Self, T>where
Self: Sized,
fn iter_mut<T: TraversalOrder>(&mut self) -> TreeIterMut<'_, Self, T>where
Self: Sized,
Creates a mutable iterator that traverses the tree starting from this node. Read more
impl<T: Eq> Eq for Node<T>
impl<T> StructuralPartialEq for Node<T>
Auto Trait Implementations§
impl<T> Freeze for Node<T>where
T: Freeze,
impl<T> RefUnwindSafe for Node<T>where
T: RefUnwindSafe,
impl<T> Send for Node<T>where
T: Send,
impl<T> Sync for Node<T>where
T: Sync,
impl<T> Unpin for Node<T>where
T: Unpin,
impl<T> UnwindSafe for Node<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more