TreeNode

Struct TreeNode 

Source
pub struct TreeNode<T>
where T: Display,
{ /* private fields */ }
Expand description

Denotes a node in the tree, and any node can be the root of a tree when output. The generic parameter T must implement Display which is used to generate the label for each node in the output.

Note that From<T> is implemented allowing a nice short-cut for node creation, and From<&T> is also implemented for types that also implement Clone.

Implementations§

Source§

impl<T> TreeNode<T>
where T: Display,

Source

pub fn new(data: T) -> Self

Construct a new tree node with the provided data value.

Source

pub fn with_children(data: T, children: impl Iterator<Item = T>) -> Self
where T: Sized,

Construct a new tree node with the provided data value and an iterator that provides child data items.

Source

pub fn with_child_nodes( data: T, children: impl Iterator<Item = TreeNode<T>>, ) -> Self
where T: Sized,

Construct a new tree node with the provided data value and an iterator that provides pre-constructed TreeNode values as child nodes.

Source

pub fn data(&self) -> &T

Return a reference to the data item for this node.

Source

pub fn label(&self) -> String

Return the label for this node.

Source

pub fn has_children(&self) -> bool

Returns true if this node has child nodes, else false.

Source

pub fn children(&self) -> impl Iterator<Item = &TreeNode<T>>

Returns an iterator that will return all the child nodes.

Source

pub fn push(&mut self, data: T)

Push a new data item into the list of children.

Source

pub fn push_node(&mut self, child: TreeNode<T>)

Push a new pre-constructed TreeNode into the list of children.

Source

pub fn extend<V>(&mut self, children: impl Iterator<Item = T>)

Extend the list of children with each data item from the provided iterator.

Source

pub fn to_string_with_format(&self, format: &TreeFormatting) -> Result<String>

Return a string containing the generated tree text formatted according to the provided format settings.

Note: in effect Display::fmt calls this method with default formatting.

Source

pub fn write(&self, to_writer: &mut impl Write) -> Result<()>
where T: Display,

Write this tree to the provided implementation of std::io::Write with default formatting.

Source

pub fn write_with_format( &self, to_writer: &mut impl Write, format: &TreeFormatting, ) -> Result<()>
where T: Display,

Write this tree to the provided implementation of std::io::Write with the provided format settings.

Trait Implementations§

Source§

impl<T> Clone for TreeNode<T>
where T: Display + Clone,

Source§

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

Returns a duplicate 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 for TreeNode<T>
where T: Display + Debug,

Source§

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

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

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

Source§

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

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

impl<T> From<&T> for TreeNode<T>
where T: Display + Clone,

Source§

fn from(v: &T) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for TreeNode<String>

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for TreeNode<T>
where T: Display,

Source§

fn from(v: T) -> Self

Converts to this type from the input type.
Source§

impl<T> PartialEq for TreeNode<T>
where T: Display + PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

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

§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.