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).
Key Properties
Section titled “Key Properties”- Zero global / TLS state: Every graph lives inside an explicit
Scope(orSyncScope). Ideal for multi-tenant servers, isolated SSR scopes, TUI loops, and deterministic tests. Copyscope-bound handles (Atom<T>,Computed<T>,Signal<T>): Capture signals freely inmoveclosures without.clone()boilerplate.- Zero-copy reads: Read values via
.with(sig, |v| ...)or.get_rc(sig)/.get_arc(sig)without requiringT: 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
Subscriptionguards & panic-safe flushing: Subscriptions clean up automatically onDrop, and a panicking subscriber never poisons remaining queued effects orbatch_depth. - 5 zero-cost extension slots (
internal): Composes cleanly withzwire-tx,zwire-protocol, and reactivezwire-collectionswith zero circular dependencies.
Quick Start
Section titled “Quick Start”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