Crate arena_tree

Source
Expand description

A DOM-like tree data structure based on &Node references.

Any non-trivial tree involves reference cycles (e.g. if a node has a first child, the parent of the child is that node). To enable this, nodes need to live in an arena allocator such as arena::TypedArena distrubuted with rustc (which is #[unstable] as of this writing) or typed_arena::Arena.

If you need mutability in the node’s data, make it a cell (Cell or RefCell) or use cells inside of it.

§Example

extern crate typed_arena;
extern crate arena_tree;
use std::cell::RefCell;

let arena = typed_arena::Arena::new();
let a = arena.alloc(arena_tree::Node::new(RefCell::new(String::new())));
let b = arena.alloc(arena_tree::Node::new(RefCell::new(String::new())));
a.append(b);
b.data.borrow_mut().push_str("content");
assert_eq!(a.descendants().map(|node| node.data.borrow().clone()).collect::<Vec<_>>(), [
    "".to_string(), "content".to_string()
]);

Structs§

Ancestors
An iterator of references to the ancestors a given node.
Children
An iterator of references to the children of a given node.
Descendants
An iterator of references to a given node and its descendants, in tree order.
FollowingSiblings
An iterator of references to the siblings after a given node.
Node
A node inside a DOM-like tree.
PrecedingSiblings
An iterator of references to the siblings before a given node.
ReverseChildren
An iterator of references to the children of a given node, in reverse order.
ReverseTraverse
An iterator of the start and end edges of a given node and its descendants, in reverse tree order.
Traverse
An iterator of the start and end edges of a given node and its descendants, in tree order.

Enums§

NodeEdge