| Crates.io | treelog |
| lib.rs | treelog |
| version | 0.1.0-beta.0 |
| created_at | 2025-11-26 17:04:44.457216+00 |
| updated_at | 2025-11-28 17:21:57.461895+00 |
| description | A highly customizable, optimized, and modular tree rendering library |
| homepage | https://github.com/muijf/treelog |
| repository | https://github.com/muijf/treelog |
| max_upload_size | |
| id | 1951844 |
| size | 450,864 |

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
Add this to your Cargo.toml:
[dependencies]
treelog = "0.1.0-beta.0"
# Install from crates.io
cargo install treelog --features cli,arbitrary-walkdir,serde-json
# Or build from source
git clone https://github.com/muijf/treelog
cd treelog
cargo build --release --bin treelog --features cli,arbitrary-walkdir,serde-json
Note: The CLI requires the
clifeature. Enable additional features based on the input sources you need. You can use convenience aliases likewalkdir(forarbitrary-walkdir).
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 (requires colored)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 formatsExact Serialization (Round-Trip):
serde - Meta-feature enabling all serde serializationEnables 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):
arbitrary - Meta-feature enabling all arbitrary conversionsEnables all of the following:
arbitrary-json - Convert any JSON to Tree (requires serde-json)arbitrary-yaml - Convert any YAML to Tree (requires serde-yaml)arbitrary-toml - Convert any TOML to Tree (requires serde-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 structuresYou can also enable individual features instead of the meta-feature.
Convenience Aliases:
walkdir - Alias for arbitrary-walkdirpetgraph - Alias for arbitrary-petgraphcargo-metadata - Alias for arbitrary-cargogit2 - Alias for arbitrary-git2syn - Alias for arbitrary-syntree-sitter - Alias for arbitrary-tree-sitterclap - Alias for arbitrary-clap (also used by CLI)cli - CLI binary (includes clap)Quick examples:
# Common feature set
treelog = { version = "0.1.0-beta.0", features = ["traversal", "transform", "path", "compare", "merge", "export"] }
# Enable everything
treelog = { version = "0.1.0-beta.0", features = ["all"] }
Note: The
clifeature is separate and must be enabled explicitly for the binary. Use convenience aliases likewalkdir(forarbitrary-walkdir) when available.
use treelog::{Tree, renderer::write_tree};
let tree = Tree::Node("root".to_string(), vec![
Tree::Leaf(vec!["item1".to_string()]),
Tree::Node("sub".to_string(), vec![
Tree::Leaf(vec!["subitem1".to_string()]),
Tree::Leaf(vec!["subitem2".to_string()]),
]),
]);
let mut output = String::new();
write_tree(&mut output, &tree).unwrap();
println!("{}", output);
Output:
root
├─ item1
└─ sub
├─ subitem1
└─ subitem2
For more examples and usage patterns, see the examples.
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.
# Visualize a directory structure
treelog from dir . --max-depth 3
# Visualize Cargo dependencies
treelog from cargo
# Visualize Git repository structure
treelog from git .
# Render a tree from a file (JSON/YAML/TOML/RON)
treelog render tree.json
# Render a tree from stdin
cat tree.json | treelog render
# Get tree statistics
treelog from dir . --format json | treelog stats
# Filesystem & Git
treelog from dir <path> [--max-depth <n>] # arbitrary-walkdir
treelog from git [path] [--branches] [--commit] # arbitrary-git2
# Code & AST
treelog from rust <file> # arbitrary-syn
treelog from tree-sitter <file> [--language] # arbitrary-tree-sitter
treelog from xml <file> # arbitrary-xml
# Package Managers
treelog from cargo [--manifest <path>] [--package <name>] # arbitrary-cargo
# Data Formats
treelog from json <file> # serde-json
treelog from yaml <file> # serde-yaml
treelog from toml <file> # serde-toml
treelog from ron <file> # serde-ron
# Styles
treelog from dir . --style ascii
treelog from dir . --custom-style ">-,<-,| , "
# Output
treelog from dir . --output tree.txt
treelog from dir . --format json > tree.json
treelog from dir . --format html > tree.html
treelog from dir . --format svg > tree.svg
treelog from dir . --format dot > tree.dot
# Basic operations
treelog render tree.json # Render from file
treelog render - # Render from stdin
treelog stats tree.json # Get statistics
treelog search "pattern" tree.json # Search nodes/leaves
# Manipulation
treelog sort --method label tree.json
treelog sort --method depth --reverse tree.json
treelog transform map-nodes "[{}]" tree.json
treelog transform filter "src" tree.json
# Comparison & Merging
treelog compare tree1.json tree2.json
treelog merge --strategy append tree1.json tree2.json
# Export
treelog export html tree.json > output.html
treelog export svg tree.json > output.svg
treelog export dot tree.json > output.dot
# Create tree and get statistics
treelog from dir . --format json | treelog stats
# Transform and export
treelog from dir . --format json | treelog transform filter "src" | treelog export html > output.html
Note: When piping between commands, use
--format json(oryaml,toml,ron) to serialize the tree structure. The defaulttextformat is for human-readable output only.
treelog --help
treelog from --help
treelog from dir --help
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 exampleAdvanced 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 formatsIntegration 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 visualizationFormat code:
cargo fmt --all
Formats all Rust code according to the official style guide.
Lint code:
cargo clippy --all-targets --all-features -- -D warnings
Runs Clippy linter with all targets and features enabled, treating warnings as errors.
Run tests:
cargo test --all-features
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.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.