[][src]Crate read_tree

This crate provides a library for creating and then reading trees. The trees cannot be modified after their creation.

Usage

This crate is available on crates.io and can be used by adding read-tree to your dependencies in your projects Cargo.toml.

[dependencies]
read-tree = "0.1"

Example

Trees are created using the builder struct Sapling. Nodes can be attached to a sapling by using .push(_). When a node is added to a sapling it is also selected as the parent for later nodes. To finish a node and reselect its parent use .pop(). When adding a node with no children use .push_leaf(_); it behaves the same as .push(_); .pop();.

When the sapling is complete, you can use .build() to turn the sapling into a Tree. The resulting tree can no longer be modified. Navigating trees is done by using slices of trees called Nodes. To get started use .root() on a tree to get its root node which contains the entire tree.

Nodes support various iterators to navigate their contents.

use read_tree::Sapling;

let mut sap = Sapling::new();
sap.push(1);
sap.pop();

let tree = sap.build().unwrap();
let root = tree.root();

assert_eq!(root.data(), &1);

Structs

Children

An iterator of child nodes.

Descendants

A depth first iterator of nodes. It iterates all nodes in the subtree of the node, including the node itself.

Node

A slice of a Tree.

Sapling

A builder to construct Trees.

Tree

A read-only tree data structure.

Enums

Error

An error enum returned when attempting to build a Sapling.