
A customizable tree rendering library and CLI for Rust
Provides low-level and high-level APIs for rendering hierarchical data structures, similar to tree, npm ls, or cargo tree. Also includes a command-line utility for quick tree visualization.
Key Features: Multiple styles • Macro DSL • Builder API • Iterator support • Tree statistics & traversal • Search & filtering • Transformation & sorting • Export to HTML/SVG/DOT • Integrations with JSON/YAML/TOML, filesystem, Git, Cargo, and more
Table of Contents
Installation
As a Library
Add this to your Cargo.toml:
[]
= "0.0.6"
As a CLI Tool
# Install from crates.io
# Or build from source
Note: The CLI requires the
clifeature. Enable additional features based on the input sources you need. You can use convenience aliases likewalkdir(forarbitrary-walkdir).
Feature Flags
Most features are optional to keep the core library lightweight. Enable only what you need.
Core Features:
builder- Builder API for constructing treesiterator- Iterator API for streaming treesmacro- Macro DSL for tree constructionformatters- Custom formatters for nodes and leavescolor- Color output support (requirescolored)
Tree Operations:
traversal- Tree traversal iterators (pre-order, post-order, level-order)transform- Tree transformation operations (map, filter, prune)path- Tree path utilities (get by path, flatten)compare- Tree comparison and diff operationssearch- Tree search operations (find nodes/leaves, get paths)sort- Tree sorting operations (sort by label, depth, custom)stats- Tree statistics and metricsmerge- Tree merging with different strategiesexport- Export to HTML, SVG, and DOT formats
Exact Serialization (Round-Trip):
-
Enables all of the following:
serde-json- JSON serialization/deserialization (Tree ↔ JSON)serde-yaml- YAML serialization/deserialization (Tree ↔ YAML)serde-toml- TOML serialization/deserialization (Tree ↔ TOML)serde-ron- RON serialization/deserialization (Tree ↔ RON)
You can also enable individual features instead of the meta-feature.
Arbitrary Conversion (One-Way):
-
Enables all of the following:
arbitrary-json- Convert any JSON to Tree (requiresserde-json)arbitrary-yaml- Convert any YAML to Tree (requiresserde-yaml)arbitrary-toml- Convert any TOML to Tree (requiresserde-toml)arbitrary-xml- Convert XML/HTML to Treearbitrary-walkdir- Build trees from directory structuresarbitrary-petgraph- Convert petgraph graphs to Treearbitrary-cargo- Build trees from Cargo metadataarbitrary-git2- Build trees from Git repositoriesarbitrary-syn- Build trees from Rust ASTarbitrary-tree-sitter- Build trees from tree-sitter parse treesarbitrary-clap- Build trees from clap command structures
You can also enable individual features instead of the meta-feature.
Convenience Aliases:
walkdir- Alias forarbitrary-walkdirpetgraph- Alias forarbitrary-petgraphcargo-metadata- Alias forarbitrary-cargogit2- Alias forarbitrary-git2syn- Alias forarbitrary-syntree-sitter- Alias forarbitrary-tree-sitterclap- Alias forarbitrary-clap(also used by CLI)cli- CLI binary (includesclap)
Quick examples:
# Common feature set
= { = "0.0.6", = ["traversal", "transform", "path", "compare", "merge", "export"] }
# Enable everything
= { = "0.0.6", = ["all"] }
Note: The
clifeature is separate and must be enabled explicitly for the binary. Use convenience aliases likewalkdir(forarbitrary-walkdir) when available.
Quick Start
use ;
let tree = Node;
let mut output = Stringnew;
write_tree.unwrap;
println!;
Output:
root
├─ item1
└─ sub
├─ subitem1
└─ subitem2
For more examples and usage patterns, see the examples.
CLI Usage
The CLI tool provides a convenient way to visualize trees from various sources without writing code. All library features are available through the command-line interface.
Basic Usage
# Visualize a directory structure
# Visualize Cargo dependencies
# Visualize Git repository structure
# Render a tree from a file (JSON/YAML/TOML/RON)
# Render a tree from stdin
|
# Get tree statistics
|
Input Sources
# Filesystem & Git
# Code & AST
# Package Managers
# Data Formats
Rendering Options
# Styles
# Output
Tree Operations
# Basic operations
# Manipulation
# Comparison & Merging
# Export
Piping and Serialization
# Create tree and get statistics
|
# Transform and export
| |
Note: When piping between commands, use
--format json(oryaml,toml,ron) to serialize the tree structure. The defaulttextformat is for human-readable output only.
Help
Examples
Run any example with:
cargo run --example <name> --all-features
Core Examples:
basic- Basic tree construction and renderingbuilder- Using the builder APIiterator- Streaming large treesmacro- Using the macro DSLcustomization- Custom styles and formatterscomplex- Complex tree structuresfile_tree- File system tree example
Advanced Examples:
statistics- Tree statistics and analysistraversal- Tree traversal iteratorssearch- Tree search and query operationstransform- Tree transformation operationssorting- Tree sorting operationspath- Tree path utilitiescomparison- Tree comparison and diffmerge- Tree merging strategiesexport- Export to HTML, SVG, and DOT formats
Integration Examples:
arbitrary- Arbitrary data conversion (JSON/YAML/TOML to Tree)serde- Exact JSON and YAML serialization (Tree ↔ JSON/YAML)toml- TOML parsing and conversionfilesystem- File system tree buildingpetgraph- Graph to/from tree conversioncargo- Cargo dependency tree visualizationgit2- Git repository structure visualizationxml- XML/HTML DOM tree visualizationsyn- Rust AST visualizationron- RON serializationtree_sitter- Tree-sitter parse tree visualizationclap- Command-line argument structure visualization
Development
Format code:
Formats all Rust code according to the official style guide.
Lint code:
Runs Clippy linter with all targets and features enabled, treating warnings as errors.
Run tests:
Runs all tests with all features enabled to ensure comprehensive coverage.
Editor setup: Recommended extensions are available in
.vscode/extensions.json. See CONTRIBUTING.md for development guidelines and pre-commit hooks.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.