pub trait ReactiveGraph {
type Computed<T>: GraphNode + Copy;
type Source<T>: GraphNode + Copy;
type Effect: GraphNode + Copy;
type Scope<'a>: Teardown
where Self: 'a;
// Required methods
fn dispose_slot<T: 'static>(&self, handle: &Self::Computed<T>);
fn dispose_cell<T: 'static>(&self, handle: &Self::Source<T>);
fn dispose_effect(&self, handle: &Self::Effect);
fn scope(&self) -> Self::Scope<'_>;
fn batch<R>(&self, run: impl FnOnce(&Self) -> R) -> R;
fn dependent_count(&self, node: &impl GraphNode) -> usize;
fn dependency_count(&self, node: &impl GraphNode) -> usize;
}Expand description
The graph operations that need no bounds on node values.
Everything here — disposal, scopes, batching, degree introspection — is
about graph structure, so generic code over this trait pays for nothing it
does not use. Construction and reads live in SyncReactiveGraph /
AsyncReactiveGraph. Both capability traits expose the Cell-kernel
vocabulary: source, get, and set.
use lazily::{Context, ReactiveGraph, SyncReactiveGraph};
// Written once, no value bounds, works for every execution model.
fn leaked_edges<G: ReactiveGraph>(graph: &G, node: &G::Source<i64>) -> usize {
graph.dependent_count(node)
}
let ctx = Context::new();
let topic = SyncReactiveGraph::source(&ctx, 1i64);
let derived = SyncReactiveGraph::computed(&ctx, move |c| c.get(&topic) + 1);
assert_eq!(SyncReactiveGraph::get(&ctx, &derived), 2);
assert_eq!(leaked_edges(&ctx, &topic), 1);
ReactiveGraph::dispose_slot(&ctx, &derived);
assert_eq!(leaked_edges(&ctx, &topic), 0);Required Associated Types§
Required Methods§
Sourcefn dispose_slot<T: 'static>(&self, handle: &Self::Computed<T>)
fn dispose_slot<T: 'static>(&self, handle: &Self::Computed<T>)
Tear down a derived slot: detach both edge directions, invalidate the surviving readers, and recycle the id.
Sourcefn dispose_cell<T: 'static>(&self, handle: &Self::Source<T>)
fn dispose_cell<T: 'static>(&self, handle: &Self::Source<T>)
Tear down a source cell: detach its dependents, invalidate them, and recycle the id.
Sourcefn dispose_effect(&self, handle: &Self::Effect)
fn dispose_effect(&self, handle: &Self::Effect)
Tear down an effect, running its cleanup.
Sourcefn scope(&self) -> Self::Scope<'_>
fn scope(&self) -> Self::Scope<'_>
Open a teardown scope: nodes created through it are disposed when it ends, in reverse creation order.
Sourcefn batch<R>(&self, run: impl FnOnce(&Self) -> R) -> R
fn batch<R>(&self, run: impl FnOnce(&Self) -> R) -> R
Run run with invalidation batched until it returns.
Sourcefn dependent_count(&self, node: &impl GraphNode) -> usize
fn dependent_count(&self, node: &impl GraphNode) -> usize
How many nodes currently depend on node — the size of its reverse edge
set. Returns 0 for a disposed or unknown node.
Sourcefn dependency_count(&self, node: &impl GraphNode) -> usize
fn dependency_count(&self, node: &impl GraphNode) -> usize
How many nodes node currently depends on — the size of its forward
edge set. Returns 0 for a disposed or unknown node.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".