spruce/tree

Pure nested tree rendering.

Trees are data structures rendered with an explicit Spruce context. The default renderer uses Unicode branch glyphs when color is supported and a deterministic ASCII fallback when it is not.

Types

A nested labelled tree.

pub opaque type Tree

Values

pub fn ascii(tree: Tree) -> Tree

Force deterministic ASCII branch markers regardless of color support.

pub fn child(parent: Tree, child child: Tree) -> Tree

Add a child to parent, preserving insertion order.

pub fn enumerator(
  tree: Tree,
  branch: fn(Int, Bool) -> String,
) -> Tree

Set a custom branch enumerator for the rendered tree.

The function receives the one-based depth of the node being rendered and whether it is the last child of its parent. It should return the complete branch marker to place before that node’s first label line.

pub fn render(sp: spruce.Spruce, tree: Tree) -> String

Render a tree to a string.

pub fn root(label: String) -> Tree

Build a tree root with no children.

Search Document