Skip to main content

Tree

Struct Tree 

Source
pub struct Tree { /* private fields */ }

Implementations§

Source§

impl Tree

Source

pub fn new(label: Box<dyn Renderable + Send + Sync>) -> Self

Create a new tree node with the given label.

§Arguments
  • label - The content to display for this node.
§Example
use rich_rs::{Tree, Text};

let tree = Tree::new(Box::new(Text::plain("Root")));
Source

pub fn add(&mut self, label: Box<dyn Renderable + Send + Sync>) -> &mut Tree

Add a child node with the given label.

Returns a mutable reference to the newly created child, allowing for chaining to build nested structures.

§Arguments
  • label - The content to display for the child node.
§Returns

A mutable reference to the newly added child Tree.

§Example
use rich_rs::{Tree, Text};

let mut root = Tree::new(Box::new(Text::plain("Root")));
let child = root.add(Box::new(Text::plain("Child")));
child.add(Box::new(Text::plain("Grandchild")));
Source

pub fn add_with_options( &mut self, label: Box<dyn Renderable + Send + Sync>, options: TreeNodeOptions, ) -> &mut Tree

Add a child node with the given label and options.

Options allow overriding style, guide_style, expanded, and highlight on a per-node basis. Fields set to None inherit from the parent.

§Arguments
  • label - The content to display for the child node.
  • options - Per-node overrides.
§Returns

A mutable reference to the newly added child Tree.

Source

pub fn add_tree(&mut self, tree: Tree)

Add an existing tree as a child.

This is useful for combining pre-built subtrees.

§Arguments
  • tree - An existing Tree to add as a child.
§Example
use rich_rs::{Tree, Text};

let mut subtree = Tree::new(Box::new(Text::plain("Subtree")));
subtree.add(Box::new(Text::plain("Leaf")));

let mut root = Tree::new(Box::new(Text::plain("Root")));
root.add_tree(subtree);
Source

pub fn with_style(self, style: Style) -> Self

Set the style for the label.

§Arguments
  • style - Style to apply to the node’s label.
Source

pub fn with_guide_style(self, style: Style) -> Self

Set the style for guide lines.

§Arguments
  • style - Style to apply to guide characters.
Source

pub fn with_expanded(self, expanded: bool) -> Self

Set whether children are expanded (visible).

§Arguments
  • expanded - If true, children are rendered; if false, only this node is shown.
Source

pub fn with_highlight(self, highlight: bool) -> Self

Set whether to highlight labels.

§Arguments
  • highlight - If true, labels may be highlighted (for future use).
Source

pub fn with_hide_root(self, hide: bool) -> Self

Set whether to hide the root node.

When true, only children are rendered (no root label or root guide lines).

§Arguments
  • hide - If true, the root node’s label is hidden.
Source

pub fn children_count(&self) -> usize

Get the number of direct children.

Source

pub fn has_children(&self) -> bool

Check if this node has any children.

Source

pub fn is_expanded(&self) -> bool

Check if children are expanded.

Source

pub fn style(&self) -> Style

Get the style for labels.

Source

pub fn guide_style(&self) -> Style

Get the style for guide lines.

Source

pub fn children(&self) -> &[Tree]

Get a reference to the children.

Source

pub fn children_mut(&mut self) -> &mut Vec<Tree>

Get a mutable reference to the children.

Trait Implementations§

Source§

impl Debug for Tree

Source§

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

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

impl Renderable for Tree

Source§

fn render( &self, _console: &Console<Stdout>, options: &ConsoleOptions, ) -> Segments

Render this object to a sequence of segments.
Source§

fn measure( &self, console: &Console<Stdout>, options: &ConsoleOptions, ) -> Measurement

Measure the minimum and maximum width requirements. Read more

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl !RefUnwindSafe for Tree

§

impl Send for Tree

§

impl Sync for Tree

§

impl Unpin for Tree

§

impl !UnwindSafe for Tree

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.