Trait Children

Source
pub trait Children {
    // Required methods
    fn at(&self, index: usize) -> Option<&dyn Node>;
    fn length(&self) -> usize;
}
Expand description

Trait defining a collection of child nodes in a tree structure.

Children provides the interface for accessing and querying collections of tree nodes. Implementations can provide different storage strategies, filtering capabilities, or views of the underlying data.

§Examples

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

let mut children = NodeChildren::new();
children.append(Box::new(Leaf::new("Item 1", false)));
children.append(Box::new(Leaf::new("Item 2", false)));

assert_eq!(children.length(), 2);
assert_eq!(children.at(0).unwrap().value(), "Item 1");

Required Methods§

Source

fn at(&self, index: usize) -> Option<&dyn Node>

Returns the node at the given index.

§Arguments
  • index - The zero-based index of the desired node
§Returns

An optional reference to the node at the given index, or None if the index is out of bounds

Source

fn length(&self) -> usize

Returns the total number of children in this collection.

§Returns

The count of child nodes as a usize

Implementors§