tagtree/lib.rs
1//! Organize application data with hierarchical, slash-separated tags.
2//!
3//! `tagtree` is useful for bookmarks, documents, tasks, notes, and other items
4//! that can belong to more than one nested category. Use [`TagTree`]
5//! when the library should keep each item's complete tag assignment in sync:
6//!
7//! ```
8//! use tagtree::{normalize_paths, TagTree};
9//!
10//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
11//! let mut tree = TagTree::<u64>::new();
12//! tree.set_tags(&42, normalize_paths(["work/rust", "favorite"])?)?;
13//!
14//! assert_eq!(tree.items_under("work")?, vec![42]);
15//! assert_eq!(tree.tags_for(&42), vec!["favorite", "work/rust"]);
16//! # Ok(())
17//! # }
18//! ```
19//!
20//! A path such as `work/rust/async` is stored as a tree. Queries on `work`
21//! include items assigned to any descendant, while `tags_for` reports only the
22//! item's actual assignments. An item may appear in several branches at once.
23//! Untagged `TagTree` items are kept at the empty root path and can be queried
24//! with `items_under("")`.
25//!
26//! The [`path`] module provides path validation and normalization helpers for
27//! external input.
28
29mod error;
30mod tag_tree;
31
32pub mod path;
33mod path_tree;
34
35pub use error::{Error, Result};
36pub use path::{TagPathError, is_within, normalize_path, normalize_paths, validate_path};
37pub use path_tree::TagNode;
38pub use tag_tree::{ItemTags, TagTree, TagTreeSummary};