Crates.io | tree-formatter-rs |
lib.rs | tree-formatter-rs |
version | |
source | src |
created_at | 2025-05-08 00:37:46.747894+00 |
updated_at | 2025-05-08 00:37:46.747894+00 |
description | A simple library to format hierarchical structures as text-based trees |
homepage | https://github.com/abhishp/tree-formatter-rs |
repository | https://github.com/abhishp/tree-formatter-rs |
max_upload_size | |
id | 1664712 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A simple library to format hierarchical structures as text-based trees.
This library provides macros and formatting utilities to easily create and display tree-like structures in text output. You can customize the appearance of the tree branches and item prefixes.
Example:
Assuming you have a formatter object (e.g., tree_formatter
) that implements the necessary methods (begin_level
, end_level
, write_fmt
), you can build a tree like this:
// Import the macros (adjust path as necessary)
// use tree_formatter::{tree_indent, tree_indent_last, tree_unindent, tree_write, tree_write_last};
// Assuming 'tree_formatter' is initialized, potentially with custom formats:
// let context_fmt = ContextFormat::new(" ", "│ "); // Example: default format
// let item_fmt = ItemPrefixFormat::new("├── ", "└── "); // Example: default format
// let mut tree_formatter = TreeFormatter::new(context_fmt, item_fmt); // Hypothetical writer
tree_write!(tree_formatter, "Root Node");
// Start the first branch
tree_indent!(tree_formatter);
tree_write!(tree_formatter, "Child 1");
// Start a nested branch
tree_indent!(tree_formatter);
tree_write!(tree_formatter, "Grandchild 1.1");
tree_write_last!(tree_formatter, "Grandchild 1.2");
tree_unindent!(tree_formatter); // End nested branch
tree_write_last!(tree_formatter, "Child 2 (last in this branch)");
tree_unindent!(tree_formatter); // End first branch
// Start the second (and last) branch from root
tree_indent_last!(tree_formatter);
tree_write!(tree_formatter, "Child 3");
tree_write_last!(tree_formatter, "Child 4 (last overall)");
tree_unindent!(tree_formatter); // End second branch
// Get the final output from the writer
// let output = tree_formatter.to_string();
// println!("{}", output);