tagtree
tagtree provides in-memory data structures for organizing items under
hierarchical, slash-separated tag paths.
Use TagIndex
when items can have multiple tags and tags may be renamed or deleted. Use
Tree when
you need direct control over a path-to-items tree.
Installation
Add tagtree to your Cargo.toml:
[]
= "0.1"
The crate requires Rust 1.85 or newer.
Quick start
use TagIndex;
let mut index = new;
index.upsert;
index.upsert;
assert_eq!;
assert_eq!;
// Upserting replaces the item's previous assignments.
index.upsert;
assert_eq!;
TagIndex<T> requires T: Eq + Hash + Clone; querying items additionally
requires T: Ord so results can be returned in descending order.
Paths and tags
Paths use / as the separator, for example work/rust/async. A path must not
start or end with /, contain //, or contain a blank segment. The root path
is represented by an empty string ("").
Use normalize_tag
and normalize_tags
to trim input, skip blank values, remove duplicates, and validate paths before
storing them:
use normalize_tags;
let tags = normalize_tags?;
assert_eq!;
# Ok::
Managing assignments
TagIndex::items(path) returns items assigned to path or any descendant. An
item with no tags is stored at the root and can be queried with items("").
Path mutations return the affected items with their resulting assignments:
use TagIndex;
let mut index = new;
index.upsert;
let changed = index.rename_path?;
assert_eq!;
let removed = index.delete_path?;
assert!;
# Ok::
Unknown paths return a TreeError from rename_path, delete_path, and the
low-level Tree query methods. Removing an item with TagIndex::remove is a
no-op when the item is not present.
Lower-level tree API
Tree<T> maps paths to sets of items and supports adding, removing, moving,
and querying items. Tree::get_items includes descendants, while
Tree::get_bag only returns items directly attached to the requested node.
Tree::view produces a read-only TreeView with item counts and child nodes
for presentation.
License
Licensed under the MIT License.
Contributing
Run the checks before opening a pull request: