Skip to content

zwire-core

Zero-global, #![forbid(unsafe_code)], #![no_std] (alloc) scoped push-pull reactive arena with scope-bound Copy signal handles, forward-only unwatched links, early cutoff, cycle detection, panic-safe batch flushing, and an opt-in multi-threaded SyncScope (Send + Sync).

Part of the zwire Rust workspace (native companion to @zwire/core).

  • Zero global / TLS state: Every graph lives inside an explicit Scope (or SyncScope). Ideal for multi-tenant servers, isolated SSR scopes, TUI loops, and deterministic tests.
  • Copy scope-bound handles (Atom<T>, Computed<T>, Signal<T>): Capture signals freely in move closures without .clone() boilerplate.
  • Zero-copy reads: Read values via .with(sig, |v| ...) or .get_rc(sig) / .get_arc(sig) without requiring T: Clone, and with zero borrows/locks held during user callbacks (re-entrancy & deadlock safe).
  • Forward-only unwatched links + monotonic cycle stamps: Unwatched computeds do not retain upstream subscriber edges, promote lazily on subscribe(), cascade unwatch upstream on teardown, and deduplicate nested diamond re-reads (C1 -> a -> C2(a) -> a).
  • RAII Subscription guards & panic-safe flushing: Subscriptions clean up automatically on Drop, and a panicking subscriber never poisons remaining queued effects or batch_depth.
  • 5 zero-cost extension slots (internal): Composes cleanly with zwire-tx, zwire-protocol, and reactive zwire-collections with zero circular dependencies.
use zwire_core::Scope;
let scope = Scope::new();
let count = scope.atom(1);
let doubled = scope.computed(move |cx| cx.get(count) * 2);
let _sub = scope.subscribe(doubled, |v| {
println!("doubled = {v}");
});
scope.batch(|| {
scope.set(count, 2);
scope.update(count, |n| n + 1);
}); // fires subscriber once with 6