
A customizable tree rendering library for Rust
Provides low-level and high-level APIs for rendering hierarchical data structures, similar to tree, npm ls, or cargo tree.
Installation • Quick Start • Documentation • Examples
Features
- Multiple Styles - Unicode, ASCII, Box drawing, and custom styles
- Builder API - Fluent interface for easy tree construction
- Iterator Support - Stream large trees without materializing
- Custom Formatters - Format nodes and leaves to your needs
- Optimized - Pre-computed prefixes and efficient rendering
- Zero Dependencies - Lightweight and fast
Installation
Add this to your Cargo.toml:
[]
= "0.0.3"
Quick Start
use ;
let tree = Node;
let mut output = Stringnew;
write_tree.unwrap;
println!;
Output:
root
├─ item1
└─ sub
├─ subitem1
└─ subitem2
Usage
Basic
use ;
let tree = Node;
let mut output = Stringnew;
write_tree.unwrap;
// root
// └─ item
Builder API
use TreeBuilder;
let mut builder = new;
builder.node.leaf.node.leaf.leaf.end.leaf;
let tree = builder.build;
println!;
Low-Level API
use Tree;
let tree = Node;
println!;
Iterator API
use ;
let tree = Node;
// Stream lines
for line in lines
// Or collect all at once
let lines: = tree.to_lines;
Customization
Styles:
use ;
let tree = Node;
// Predefined styles
tree.render_to_string_with_config;
// Custom style
let style = custom;
tree.render_to_string_with_config;
Formatters (requires formatters feature):
use ;
let tree = Node;
let config = default
.with_node_formatter
.with_leaf_formatter;
tree.render_to_string_with_config;
Streaming Large Trees
use ;
use Write;
let tree = Node;
let mut stdout = stdout;
for line in lines
Performance
- Pre-computed prefixes - Efficient string buffer capacity estimation
- Iterator API - Stream large trees without materializing the entire structure
- Stack-based traversal - Memory-efficient tree walking
License
This project is licensed under the MIT License - see the LICENSE file for details.
Development
Real-time feedback: This project includes VS Code/Cursor settings (.vscode/settings.json) that configure rust-analyzer to provide real-time feedback:
- Formatting: Automatically formats on save (matches
cargo fmt) - Clippy: Shows clippy warnings/errors as you type (matches pre-commit hook settings)
- Tests: Displays test failures in the editor
Git hooks available via pre-commit (see .pre-commit-config.yaml).
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.