Expand description
§rustand
A lightweight, Zustand-inspired state management library for Rust.
rustand provides a simple, single-threaded way to manage shared state with subscription support.
It is designed to be lean, dependency-free, and easy to use.
§Core Features
- Simple API: Minimalist
get,set, andsubscribepattern. - Infallible: API methods don’t return
Result, making usage clean and idiomatic. - Zero Dependencies: Core library has no external dependencies.
§Feature Flags
single-threaded(default): Optimized for WASM or single-threaded environments. UsesRcandRefCellto avoid atomic overhead.wasm: Alias forsingle-threaded, targeting WebAssembly environments.
§Quick Start
use rustand::Store;
let store = Store::new(0);
// Subscribe to changes
let _sub = store.subscribe(|v| println!("New value: {}", v));
// Update state
store.set(|s| *s += 1);
// Get state
assert_eq!(store.get(), 1);Structs§
- Store
- A state container optimized for single-threaded usage.
- Subscription
- A handle to an active subscription.
Type Aliases§
- Subscriber
Callback - Callback function type for subscribers.
- Subscriber
Id - Unique identifier for a subscriber.
Attribute Macros§
- global_
store - Generates a
thread_local!global store for the decorated struct. The struct must implementDefault. It provides a::store()associated function to easily retrieve the store. - store_
actions - Allows writing an
impl Store<State>block directly. This macro rewrites it into an Extension Trait to satisfy Rust’s orphan rules, allowing seamlessstore.method()syntax.