# zwire-core

> Generational arena Scope and thread-safe SyncScope push-pull reactive engine for Rust.

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`](https://github.com/kjmin-dev/zwire/blob/main/rust/crates/zwire/README.md) Rust workspace (native companion to [`@zwire/core`](https://github.com/kjmin-dev/zwire#readme)).

## Key Properties

- **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`](https://github.com/kjmin-dev/zwire/blob/main/rust/crates/zwire-tx/README.md), [`zwire-protocol`](https://github.com/kjmin-dev/zwire/blob/main/rust/crates/zwire-protocol/README.md), and reactive [`zwire-collections`](https://github.com/kjmin-dev/zwire/blob/main/rust/crates/zwire-collections/README.md) with zero circular dependencies.

## Quick Start

```rust
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
```
