Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 1.93 KB

File metadata and controls

79 lines (55 loc) · 1.93 KB

tree_view

Crates.io License dependency status


What this is

A library which easily formats tree structures into a view. This can be the output of an cli or part of a view in a tui.

Tree structures just need to implement the trait TreeView.

The trait TreeView has only one implementation of the function fn to_node(&self) -> Node.

An example implementation for the struct TestMap:

#derive[Eq, Ord, PartialEq, PartialOrd]
pub struct TestMap {
    pub key: String,
    pub value: Vec<TestMap>,
}

impl ToTreeView for TestMap {
    fn to_node(&self) -> Node {
        node: self.key.clone(),
        children: self.value.iter().map(|v| v.to_node()).collect(),
    }
}

Output of a TestMap:

Root
├── Leaf1
├── Node1
│   ├── Leaf2
│   └── Node2
│       ├── Leaf3
│       └── Leaf4
├── Node3
│   └── Leaf5
└── Node4
    └── Leaf6

How to install

Using cargo

You need to install cargo on your system through your package manager or any other means.

Then you simply install it through cargo.

$ > cargo install tree_view

Using source

You need to install cargo on your system through your package manager or any other means.

The you download the repository through git or manual.

After unpacking or downloading from git you have to switch into the folder of tree_view.

Then run cargo install --path ..

$ > cd tree_view
$ > cargo install --path .

License

tree_view is dual licensed under MIT License and Apache 2 License