Skip to main content

Module tree_change

Module tree_change 

Source
Expand description

TreeChange — change notifications and stable node identifiers for tree collections.

NodeId is an opaque, stable handle for a node in a crate::TreeModel. Because TreeModel is backed by a slotmap, NodeId values survive arbitrary insertions, removals, and moves — only deleting the node itself invalidates it. TreeChange describes exactly what mutated in the tree so that projections (SortFilterTreeModel, TreeSlice) can refresh efficiently and emit fine-grained divergence hints.

Consumers typically receive TreeChange values through an observer registered via crate::TreeModel::observe_changes, which fires synchronously (before the registering call returns) after each mutation. The projections listed above subscribe internally; app code rarely needs to subscribe directly.

// TreeModel::observe_changes returns an ObserverHandle whose drop
// unregisters the callback — keep it alive for the observer's lifetime.
use teksilo_data::{TreeModel, TreeChange};
let tree: TreeModel<String> = TreeModel::new();
let _handle = tree.observe_changes(|change| {
    println!("{change:?}");
});
tree.insert_root(0, "root".to_string());
// prints: NodeInserted { parent: None, index: 0, node: NodeId(...) }

Structs§

NodeId
Opaque identifier for a node in a TreeModel.

Enums§

TreeChange
Describes a mutation to a tree structure. Emitted by TreeModel<T> automatically.