pub struct TreeNode<T> {
    pub value: T,
    pub children: Option<Vec<TreeNode<T>>>,
}
Expand description

A default implemenation of a tree node. This struct provides a series of tree traversal utilities to allow you to easily work with and modify arbitrary trees.

Fields§

§value: T

This node’s value

§children: Option<Vec<TreeNode<T>>>

The children of the current node.

Trait Implementations§

source§

impl<'a, T> BorrowedTreeNode<'a> for TreeNode<T>
where T: 'a,

source§

fn get_value_and_children_iter( &'a self ) -> (Self::BorrowedValue, Option<Self::BorrowedChildren>)

This method gets the value and children from this node. The other methods of this trait assume that the ‘Children’ list does not contain any circular references. If there are, an infinite loop will result.

§

type BorrowedValue = &'a T

A reference to the value of each node in the tree.
§

type BorrowedChildren = Iter<'a, TreeNode<T>>

The type of iterator that can be used to iterate over each node’s children collection.
source§

fn bfs_iter(&'a self) -> impl TreeIterator<Item = Self::BorrowedValue>

This method retrieves an iterator that can be used to perform Breadth First (Queue - specifically VecDeque-based) searches of a tree. Read more
source§

fn dfs_preorder_iter(&'a self) -> impl TreeIterator<Item = Self::BorrowedValue>

This method retrieves an iterator that can be used to perform Depth First Preorder searches of a tree. Read more
source§

fn dfs_postorder_iter(&'a self) -> impl TreeIterator<Item = Self::BorrowedValue>

This method retrieves an iterator that can be used to perform Depth First Postorder searches of a tree. Read more
source§

impl<T: Clone> Clone for TreeNode<T>

source§

fn clone(&self) -> TreeNode<T>

Returns a copy 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<T: Debug> Debug for TreeNode<T>

source§

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

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

impl<T: Default> Default for TreeNode<T>

source§

fn default() -> TreeNode<T>

Returns the “default value” for a type. Read more
source§

impl<'a, T> MutBorrowedTreeNode<'a> for TreeNode<T>
where T: 'a,

source§

fn get_value_and_children_iter_mut( &'a mut self ) -> (Self::MutBorrowedValue, Option<Self::MutBorrowedChildren>)

This method gets the value and children from this node. The other methods of this trait assume that the ‘Children’ list does not contain any circular references. If there are, an infinite loop will result.

§

type MutBorrowedValue = &'a mut T

A mutable reference to the value of each node in the tree.
§

type MutBorrowedChildren = IterMut<'a, TreeNode<T>>

The type of iterator that can be used to iterate over each node’s children collection.
source§

fn bfs_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue>

This method retrieves an iterator that can be used to perform Breadth First (VecDeque-based) searches of a tree. Read more
source§

fn dfs_preorder_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue>

This method retrieves an iterator that can be used to perform Depth First Preorder searches of a tree. Read more
source§

fn dfs_postorder_iter_mut( &'a mut self ) -> impl TreeIteratorMut<Item = Self::MutBorrowedValue>

This method retrieves an iterator that can be used to perform Depth First Postorder searches of a tree. Read more
source§

impl<T> OwnedTreeNode for TreeNode<T>

source§

fn get_value_and_children( self ) -> (Self::OwnedValue, Option<Self::OwnedChildren>)

This method gets the value and children from this node. The other methods of this trait assume that the ‘Children’ list does not contain any circular references. If there are, an infinite loop will result.

§

type OwnedValue = T

The value of each node in the tree.
§

type OwnedChildren = IntoIter<TreeNode<T>>

The type of iterator that can be used to iterate over each node’s children collection.
source§

fn bfs(self) -> impl TreeIteratorMut<Item = Self::OwnedValue>

This method retrieves an iterator that can be used to perform Breadth First (Queue - specifically VecDeque-based) searches of a tree. Read more
source§

fn dfs_preorder(self) -> impl TreeIteratorMut<Item = Self::OwnedValue>

This method retrieves an iterator that can be used to perform Depth First Preorder searches of a tree. Read more
source§

fn dfs_postorder(self) -> impl TreeIteratorMut<Item = Self::OwnedValue>

This method retrieves an iterator that can be used to perform Depth First Postorder searches of a tree. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for TreeNode<T>
where T: RefUnwindSafe,

§

impl<T> Send for TreeNode<T>
where T: Send,

§

impl<T> Sync for TreeNode<T>
where T: Sync,

§

impl<T> Unpin for TreeNode<T>
where T: Unpin,

§

impl<T> UnwindSafe for TreeNode<T>
where T: UnwindSafe,

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> ToOwned for T
where T: Clone,

§

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

§

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

§

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.