oxide_core
oxide_core is the Rust-side engine for Oxide. It provides the primitives for:
- Defining reducers (
Reducer) - Owning state in an engine (
ReducerEngine) - Streaming revisioned snapshots (
StateSnapshot<T>) - Optional persistence helpers (feature-gated)
This crate is intentionally usage-agnostic. For end-to-end Rust ↔ Flutter wiring, see the repository examples and the root README.
Add It To Your Crate
In your Cargo.toml:
[]
= "0.1.0"
When working inside this repository, use a combined version + path dependency (Cargo prefers path locally, while published crates resolve by version):
= { = "0.1.0", = "../rust/oxide_core" }
Core Concepts
Reducer
Reducers are stateful controllers that mutate state in response to actions and side-effects:
use ;
;
ReducerEngine
ReducerEngine<R> is the async-safe facade for dispatching actions and observing snapshots:
use ReducerEngine;
# use ;
# use mpsc;
#
#
#
#
#
#
# ;
#
let runtime = new.unwrap;
runtime.block_on;
Async Runtime Behavior
ReducerEngine starts an internal async loop to process side-effects. Engine creation is safe even when there is no ambient Tokio runtime (for example, when entered from a synchronous FFI boundary):
- If a Tokio runtime is currently available, Oxide spawns tasks onto it.
- Otherwise, when built with the default
frb-spawnfeature, Oxide uses Flutter Rust Bridge’s cross-platformspawnhelper. - If
frb-spawnis disabled, Oxide falls back to an internal global Tokio runtime for background work.
In a normal Rust binary, the simplest approach is to run inside a Tokio runtime:
use ReducerEngine;
async
Invariant: No Partial Mutation On Error
Dispatch uses clone-first semantics:
- The current state is cloned.
- The reducer runs against the clone.
- If the reducer returns
StateChange::None, the clone is discarded and no snapshot is emitted. - If the reducer returns an error, the live state is not updated and no snapshot is emitted.
This makes it safe to write reducers as normal &mut State code while preserving strong error semantics.
Feature Flags
frb-spawn(default): enables FRB’sspawnhelper for cross-platform task spawningstate-persistence: enables bincode encode/decode helpers inoxide_core::persistencepersistence-json: adds JSON encode/decode helpers (requiresstate-persistence)full: enables all persistence features
Commands
From rust/:
To run benches (if enabled for your environment):
License
Dual-licensed under MIT OR Apache-2.0. See LICENSE.