Expand description
TreeModel — concrete reactive tree with shared, cloneable handles.
TreeModel<T> owns a hierarchy of T items in a flat SlotMap arena with
parent-child links. Every structural mutation (insert_root, insert_child,
remove, move_node, update) emits a TreeChange to all registered
observers before returning. Node identity is a stable, versioned NodeId
(a SlotMap key) that is never reused after removal.
Cloning produces a second handle to the same data — all handles see the
same hierarchy and receive the same change notifications. Register observers
via observe_changes; the returned
[ObserverHandle] is RAII — dropping it
unregisters the callback.
For per-view expand/collapse state wrap the model in a
TreeSlice. For sort/filter projections use
SortFilterTreeModel.
§Example
let tree = TreeModel::new();
let root = tree.insert_root(0, "root");
let child = tree.insert_child(root, 0, "child");
assert_eq!(tree.root_count(), 1);
assert_eq!(tree.child_count(root), 1);
assert_eq!(tree.parent(child), Some(root));
let clone = tree.clone();
clone.insert_root(1, "root2");
assert_eq!(tree.root_count(), 2); // both handles share the same dataStructs§
- Tree
Model - A concrete reactive tree that stores a hierarchy of
Titems in a flat arena.