Trait Node

Source
pub trait Node: Display + CloneNode {
    // Required methods
    fn value(&self) -> String;
    fn children(&self) -> Box<dyn Children>;
    fn hidden(&self) -> bool;
    fn set_hidden(&mut self, hidden: bool);
    fn set_value(&mut self, value: String);

    // Provided methods
    fn get_enumerator(&self) -> Option<&Enumerator> { ... }
    fn get_indenter(&self) -> Option<&Indenter> { ... }
    fn get_item_style(&self) -> Option<&Style> { ... }
    fn get_enumerator_style(&self) -> Option<&Style> { ... }
    fn get_item_style_func(&self) -> Option<&StyleFunc> { ... }
    fn get_enumerator_style_func(&self) -> Option<&StyleFunc> { ... }
}
Expand description

Trait defining a node in a tree structure.

Node represents an individual element in a tree that can have a value, children, visibility state, and various styling options. It supports both simple leaf nodes and complex tree nodes with nested children.

§Core Functionality

  • Value: Each node has a string value that represents its content
  • Children: Nodes can have child nodes forming a hierarchical structure
  • Visibility: Nodes can be hidden from rendering
  • Styling: Nodes support custom enumerators, indenters, and styling functions

§Examples

use lipgloss_tree::{Tree, Leaf, Node, Children};

// Create a simple leaf node
let leaf = Leaf::new("Hello", false);
assert_eq!(leaf.value(), "Hello");
assert!(!leaf.hidden());

// Create a tree node with children
let tree = Tree::new()
    .root("Parent")
    .child(vec!["Child 1".into(), "Child 2".into()]);
assert_eq!(tree.value(), "Parent");
assert_eq!(tree.children().length(), 2);

Required Methods§

Source

fn value(&self) -> String

Returns the string value of this node.

The value is the textual content that will be displayed when the tree is rendered.

§Returns

The node’s value as a String

Source

fn children(&self) -> Box<dyn Children>

Returns the children of this node.

Children are returned as a boxed trait object to allow for different implementations of the Children trait.

§Returns

A Box<dyn Children> containing this node’s children

Source

fn hidden(&self) -> bool

Returns whether this node is hidden from rendering.

Hidden nodes are not displayed in the tree output and are typically filtered out during rendering.

§Returns

true if the node is hidden, false otherwise

Source

fn set_hidden(&mut self, hidden: bool)

Sets the visibility state of this node.

§Arguments
  • hidden - true to hide the node, false to show it
Source

fn set_value(&mut self, value: String)

Updates the value of this node.

§Arguments
  • value - The new string value for this node

Provided Methods§

Source

fn get_enumerator(&self) -> Option<&Enumerator>

Returns the custom enumerator function for this node, if any.

The enumerator function generates branch characters (like ├──, └──) for this specific node, overriding the default renderer behavior.

§Returns

An optional reference to the node’s custom enumerator function

Source

fn get_indenter(&self) -> Option<&Indenter>

Returns the custom indenter function for this node, if any.

The indenter function generates indentation strings for child content under this node, overriding the default renderer behavior.

§Returns

An optional reference to the node’s custom indenter function

Source

fn get_item_style(&self) -> Option<&Style>

Returns the base item style for this node, if any.

The base item style is applied to the node’s content before any style functions are applied.

§Returns

An optional reference to the node’s base item style

Source

fn get_enumerator_style(&self) -> Option<&Style>

Returns the base enumerator style for this node, if any.

The base enumerator style is applied to the node’s branch characters before any style functions are applied.

§Returns

An optional reference to the node’s base enumerator style

Source

fn get_item_style_func(&self) -> Option<&StyleFunc>

Returns the item style function for this node, if any.

The item style function provides dynamic styling based on the node’s position and context within its parent’s children.

§Returns

An optional reference to the node’s item style function

Source

fn get_enumerator_style_func(&self) -> Option<&StyleFunc>

Returns the enumerator style function for this node, if any.

The enumerator style function provides dynamic styling for branch characters based on the node’s position and context.

§Returns

An optional reference to the node’s enumerator style function

Trait Implementations§

Source§

impl From<&str> for Box<dyn Node>

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Leaf> for Box<dyn Node>

Source§

fn from(leaf: Leaf) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Box<dyn Node>

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Tree> for Box<dyn Node>

Source§

fn from(tree: Tree) -> Self

Converts to this type from the input type.

Implementors§