zwire
Zero-dependency, #![forbid(unsafe_code)], #![no_std] (alloc), Rust 1.100 (Edition 2024) transactional reactive state engine for Rust — combining a scoped push-pull arena (Copy handles + SyncScope), rebaseable optimistic mutation layers + STM read-verify drafts, exact incremental 2-level Chunked B-Tree Top-K collections, and open JSON wire protocols compatible with @zwire/core.
Feature Flags & Modular Workspace
Use the umbrella zwire crate with granular feature flags, or depend directly on any standalone crate:
| Crate | Feature | Standalone? | What It Provides |
|---|---|---|---|
zwire-collections |
collections |
✅ | Exact 2-level Chunked B-Tree + O(1) Top-K boundary pruning (zero T: Clone) |
zwire-core |
core, sync |
✅ | Zero-global Scope + Copy handles + deadlock-free SyncScope (Send + Sync) |
zwire-tx |
tx |
core |
OptimisticLayer, RAII OptimisticGuard, atomic zero-flicker try_settle, STM Draft |
zwire-protocol |
protocol |
core |
Zero-dep JSON WireValue, out-of-order hydrate/dehydrate, ExternalSource, SyncBridge, InspectorHook |
# Only exact incremental Top-K collections (no_std + alloc, zero deps)
= { = "0.1", = false, = ["collections"] }
# Full transactional reactive engine + multi-threaded SyncScope + @zwire/core wire protocol
= "0.1"
Quick Start
use *;
let scope = new;
// 1. Reactive incremental Top-K collection (O(log N) updates, O(1) boundary skip)
let book = with_filter;
let top3 = book.top_k_signal;
let best_price = scope.computed;
book.upsert_many;
assert_eq!;
// 2. Overlapping rebaseable optimistic layers + RAII auto-revert guard
let balance = scope.atom;
let mut l1 = new;
l1.update; // UI: 800
// Authoritative server push arrives concurrently -> active intents auto-rebase!
scope.set;
assert_eq!;
// Atomic zero-flicker settle
l1.settle_with;
assert_eq!;
Running the Example & Tests
See docs/RUST-1.100-GUIDELINES.md for Rust 1.100 patterns, Clippy configuration, and invariants.
Ownership, notifications and async transactions
scope.owner()creates a lexical owner.owner.atom(...),owner.computed(...), andowner.track(handle)bind nodes to its lifetime. A nestedowner.child()can release its own graph earlier. Both local and thread-safe scopes support owners.scope.changed(signal).awaitobserves the next change.scope.changes(signal)subscribes once and supports repeatedchanged().awaitorpoll_next(cx). Writes coalesce until the consumer polls. Items containRc<T>locally orArc<T>forSyncScope. Disposed signals end the stream. With an existing futures dependency, wrap it asfutures_util::stream::poll_fn(move |cx| changes.poll_next(cx)).run_optimistic(&scope, apply, request, commit).awaitandrun_sync_optimisticbind an optimistic layer to a request's lifetime. Cancellation and request failure revert its intents. The sync commit callback stages server values in aSyncSettlement.- Implement
zwire::optics::Lens<S, A>to read and mutate a field and expose it as a subscribable computed. - Enable the
deriveCargo feature to deriveWireCodecon concrete named-field structs. With the facade, put#[wire(crate = zwire::protocol)]under#[derive(WireCodec)]. Nesting, nullable fields and safe-integer string encoding follow each field's codec.