An immutable tree data structure for fast path operations.
PathTree
is inexpensive to clone and supports prepending and appending paths to one
another. Useful when several objects in a tree need to store their path relative to the root.
``` use pathtree::PathTree;
let path = PathTree::empty(); let path = path.appendsegment(7); let path = path.appendsegment(5); let path = path.prependsegment(6); let path = path.prependsegment(8);
let pathvec: Vec<_> = path.iter().copied().collect(); asserteq!(path_vec, vec![8, 6, 7, 5]);
let other_path = PathTree::empty();
let otherpath = otherpath.appendsegment(2); let otherpath = otherpath.prependsegment(1); let otherpath = otherpath.appendsegment(3); let otherpath = otherpath.prependsegment(4);
let fullpath = otherpath.append(&path); let fullpathvec: Vec<_> = fullpath.iter().copied().collect(); asserteq!(fullpathvec, vec![4, 1, 2, 3, 8, 6, 7, 5]); ```