Crate text_trees

Simple textual output for tree-like structures.

MIT License Minimum Rust Version Rust GitHub stars crates.io docs.rs

This crate is another that will output a tree structure in text. Similar to the existing ascii_tree crate, however it is more flexible in its formatting options.

Example

The following creates a StringTreeNode using a combination of with_child_nodes and with_children that demonstrates the structure of the tree well.

```rust use text_trees::StringTreeNode;

fn maketree() -> StringTreeNode { StringTreeNode::withchildnodes( "root".tostring(), vec![ "Uncle".into(), StringTreeNode::withchildnodes( "Parent".tostring(), vec![ StringTreeNode::withchildren( "Child 1".tostring(), vec!["Grand Child 1".into()].intoiter(), ), StringTreeNode::withchildnodes( "Child 2".tostring(), vec![StringTreeNode::withchildnodes( "Grand Child 2".tostring(), vec![StringTreeNode::withchildren( "Great Grand Child 2".tostring(), vec!["Great Great Grand Child 2".tostring()].intoiter(), )] .intoiter(), )] .intoiter(), ), ] .intoiter(), ), StringTreeNode::withchildren( "Aunt".tostring(), vec!["Child 3".tostring()].intoiter(), ), ] .intoiter(), ) } ```

The tree implements Display and therefore provides a to_string method. It also has a to_string_with_format method that allows for customization of the output format. Finally, it has two write methods that take implementations of std::io::Write and will serialize accordingly.

```rust use text_trees::{FormatCharacters, TreeFormatting, TreeNode};

fn asciitree(tree: TreeNode) { let result = tree.tostringwithformat( &TreeFormatting::dirtree(FormatCharacters::ascii()) ); assert!(result.isok());

// ... do something else

} ```

This results in a textual representation of the tree as follows.

text root +-- Uncle +-- Parent | +-- Child 1 | | '-- Grand Child 1 | '-- Child 2 | '-- Grand Child 2 | '-- Great Grand Child 2 | '-- Great Great Grand Child 2 '-- Aunt '-- Child 3

Changes

Version 0.1.2

Version 0.1.1

Version 0.1.0

TODO

TBD