pub struct Node<T> { /* private fields */ }Expand description
Represents the minimum unit in a tree, containing a value of type T and all those nodes children of the node itself, if any.
Implementations§
source§impl<T> Node<T>
impl<T> Node<T>
sourcepub fn preorder<F>(&self, f: F)where
F: FnMut(&Self),
pub fn preorder<F>(&self, f: F)where F: FnMut(&Self),
Calls the given closure for each node in the tree rooted by self following then pre-order traversal.
sourcepub fn preorder_mut<F>(&mut self, f: F)where
F: FnMut(&mut Self),
pub fn preorder_mut<F>(&mut self, f: F)where F: FnMut(&mut Self),
Calls the given closure for each node in the tree rooted by self following then pre-order traversal.
sourcepub fn postorder<F>(&self, f: F)where
F: FnMut(&Self),
pub fn postorder<F>(&self, f: F)where F: FnMut(&Self),
Calls the given closure for each node in the tree rooted by self following the post-order traversal.
sourcepub fn postorder_mut<F>(&mut self, f: F)where
F: FnMut(&mut Self),
pub fn postorder_mut<F>(&mut self, f: F)where F: FnMut(&mut Self),
Calls the given closure for each node in the tree rooted by self following the post-order traversal.
sourcepub fn reduce<F, R>(&self, f: F) -> Rwhere
F: FnMut(&Self, Vec<R>) -> R,
R: Sized,
pub fn reduce<F, R>(&self, f: F) -> Rwhere F: FnMut(&Self, Vec<R>) -> R, R: Sized,
Calls the given closure recursivelly along the tree rooted by self. This method traverses the tree in post-order, and so the second parameter of f is a vector containing the returned value of f for each child in that node given as the first parameter.
sourcepub fn reduce_mut<F, R>(&mut self, f: F) -> Rwhere
F: FnMut(&mut Self, Vec<R>) -> R,
R: Sized,
pub fn reduce_mut<F, R>(&mut self, f: F) -> Rwhere F: FnMut(&mut Self, Vec<R>) -> R, R: Sized,
Calls the given closure recursivelly along the tree rooted by self. This method traverses the tree in post-order, and so the second parameter of f is a vector containing the returned value of f for each child in that node given as the first parameter.
sourcepub fn cascade<F, R>(&self, base: R, f: F)where
F: FnMut(&Self, &R) -> R,
R: Sized,
pub fn cascade<F, R>(&self, base: R, f: F)where F: FnMut(&Self, &R) -> R, R: Sized,
Calls the given closure recursivelly along the tree rooted by self. This method traverses the tree in pre-order, and so the second parameter of f is the returned value of calling f on the parent of that node given as the first parameter.
sourcepub fn cascade_mut<F, R>(&mut self, base: R, f: F)where
F: FnMut(&mut Self, &R) -> R,
R: Sized,
pub fn cascade_mut<F, R>(&mut self, base: R, f: F)where F: FnMut(&mut Self, &R) -> R, R: Sized,
Calls the given closure recursivelly along the tree rooted by self. This method traverses the tree in pre-order, and so the second parameter of f is the returned value of calling f on the parent of that node given as the first parameter.
source§impl<T> Node<T>
impl<T> Node<T>
pub fn new(value: T) -> Self
sourcepub fn children_mut(&mut self) -> &mut [Node<T>]
pub fn children_mut(&mut self) -> &mut [Node<T>]
Returns a mutable slice of all node’s children.
sourcepub fn add_child(&mut self, child: Node<T>) -> usize
pub fn add_child(&mut self, child: Node<T>) -> usize
Adds a new child to the node and returns its total number of children.
sourcepub fn remove_child(&mut self, index: usize) -> Option<Node<T>>
pub fn remove_child(&mut self, index: usize) -> Option<Node<T>>
Removes the children located at the given index and returns it, if any.
sourcepub fn children_len(&self) -> usize
pub fn children_len(&self) -> usize
Returns the total of direct descendants (children) the node has.