Struct Node

Source
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 {
            value: 2,
            children: vec![],
        },
        Node {
            value: 3,
            children: vec![],
        },
    ],
};

// 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: T

The value stored in this node.

§children: Vec<Node<T>>

The children of this node.

Trait Implementations§

Source§

impl<T> TreeNode for Node<T>

Implementation of TreeNode for Node<T>.

This allows immutable iteration over the tree.

Source§

fn children(&self) -> impl DoubleEndedIterator<Item = &Self> + '_

Returns an iterator over the children of this node.

Source§

fn iter<T: TraversalOrder>(&self) -> TreeIter<'_, Self, T>
where Self: Sized,

Creates an iterator that traverses the tree starting from this node. Read more
Source§

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> + '_

Returns a mutable iterator over the children of this node.

Source§

fn iter_mut<T: TraversalOrder>(&mut self) -> TreeMutIter<'_, Self, T>
where Self: Sized,

Creates a mutable iterator that traverses the tree starting from this node. Read more

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