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,
impl<T> TreeNode<T>where
T: Display,
Sourcepub fn with_children(data: T, children: impl Iterator<Item = T>) -> Selfwhere
T: Sized,
pub fn with_children(data: T, children: impl Iterator<Item = T>) -> Selfwhere
T: Sized,
Construct a new tree node with the provided data value and an iterator that provides child data items.
Sourcepub fn with_child_nodes(
data: T,
children: impl Iterator<Item = TreeNode<T>>,
) -> Selfwhere
T: Sized,
pub fn with_child_nodes(
data: T,
children: impl Iterator<Item = TreeNode<T>>,
) -> Selfwhere
T: Sized,
Construct a new tree node with the provided data value and an iterator that provides
pre-constructed TreeNode values as child nodes.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has child nodes, else false.
Sourcepub fn children(&self) -> impl Iterator<Item = &TreeNode<T>>
pub fn children(&self) -> impl Iterator<Item = &TreeNode<T>>
Returns an iterator that will return all the child nodes.
Sourcepub fn push_node(&mut self, child: TreeNode<T>)
pub fn push_node(&mut self, child: TreeNode<T>)
Push a new pre-constructed TreeNode into the list of children.
Sourcepub fn extend<V>(&mut self, children: impl Iterator<Item = T>)
pub fn extend<V>(&mut self, children: impl Iterator<Item = T>)
Extend the list of children with each data item from the provided iterator.
Sourcepub fn to_string_with_format(&self, format: &TreeFormatting) -> Result<String>
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.
Sourcepub fn write(&self, to_writer: &mut impl Write) -> Result<()>where
T: Display,
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.
Sourcepub fn write_with_format(
&self,
to_writer: &mut impl Write,
format: &TreeFormatting,
) -> Result<()>where
T: Display,
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.