Skip to main content

rust_elm/
lib.rs

1//! # rust-elm
2//!
3//! A Rust port of The Elm Architecture
4//!
5//! - **Pure descriptions**: `Cmd`, `Effect`, and `Sub` are data — interpretation lives in [`Runtime`] (requires `runtime` feature).
6//! - **Zero-cost updates**: `update` uses fn pointers; no `Box<dyn Fn>` on hot paths.
7//! - **Composition**: [`Slot`](component::Slot), [`optics`](optics), [`Reducer`](reducer::Reducer) / `CombineReducers`.
8//!
9//! ## Source layout
10//!
11//! | Directory | Role |
12//! |-----------|------|
13//! | [`core/`](core) | `Cmd`, `Effect`, `Sub`, `Program`, `bus` — pure data |
14//! | [`compose/`](compose) | `Reducer`, `ScopeReducer`, `safe_reducer`, optics |
15//! | [`infra/`](infra) | `Environment`, `Shared`, replay |
16//! | [`runtime/`](runtime) | Store, Tokio interpreter, subscriptions (`runtime` feature) |
17//! | [`testing/`](testing) | `TestRuntime`, `ExhaustiveTestStore`, macros |
18
19#![allow(
20    non_snake_case,
21    unpredictable_function_pointer_comparisons,
22)]
23
24pub mod compose;
25pub mod core;
26pub mod infra;
27#[cfg(feature = "runtime")]
28pub mod runtime;
29pub mod testing;
30
31// Flat re-exports — stable public API.
32pub use core::{batch, bus, cmd, effect, error, interp, program, sub};
33pub use compose::{component, optics, reducer, safe_reducer, scope};
34pub use infra::{env, replay, shared};
35pub use testing::{macros, test_runtime, test_support};
36#[cfg(feature = "runtime")]
37pub use testing::test_store;
38#[cfg(feature = "runtime")]
39pub use runtime::{store, subscription};
40
41/// Re-export keypath types for state/action focusing (see `optics`).
42pub mod keypath {
43pub use key_paths_core::{FieldDiff, hash_value, KeyPath, KpTrait, Readable, RefKpTrait, Writable};
44    pub use rust_key_paths::{EnumKp, EnumKpType, EnumValueKpType, Kp};
45}
46
47pub use batch::batch;
48pub use bus::{Bus, BusSender};
49pub use cmd::Cmd;
50pub use component::{lift, Slot};
51pub use effect::{Effect, EffectId, EnvTaskFn, RunSender, TaskFn};
52pub use dependencies::{
53    Clock, ClockDep, ClockKey, DepRng, DependencyError, DependencyKey, DependencyValues,
54    LiveRng, LiveUuidGen, Now, NowDep, NowKey, RealClock, RngDep, RngKey, SeededRng,
55    SeededUuidGen, TestClock, TestNow, UuidDep, UuidGen, UuidKey,
56};
57pub use rust_dependencies as dependencies;
58pub use env::{defer_batch, Environment, FakeClock, MockHttp};
59pub use error::EffectError;
60pub use interp::{flatten_effects, normalize, InterpretCtx};
61pub use rust_identified_vec::{Identifiable, IdentifiedVec};
62pub use optics::{
63    enum_err, enum_ok, enum_some, enum_variant, variant_of, CasePath, Casepath, EnumKp,
64    EnumKpType, EnumValueKpType, Kp,
65};
66pub use program::{Program, ReducerProgram};
67pub use safe_reducer::{safe_reduce_rollback, safe_reduce_update, SafeReduceError};
68pub use reducer::{coerce_fn, CatchReducer, CombineReducers, Reduce, Reducer, RollbackCatchReducer};
69pub use replay::{ReplayHarness, ReplayLog};
70#[cfg(feature = "serde")]
71pub use replay::StateSnapshot;
72#[cfg(feature = "runtime")]
73pub use runtime::{Runtime, RuntimeConfig, RwRuntime};
74#[cfg(all(feature = "runtime", feature = "arc-swap"))]
75pub use runtime::SwapRuntime;
76pub use scope::{
77    lift_cmd, lift_cmd_with_id, ForEachReducer, IfCaseLetReducer, IfLetReducer, OptionalReducer,
78    ScopeReducer,
79};
80pub use shared::{InMemoryStorage, Shared, SharedSubscriber, Storage, StorageError};
81#[cfg(feature = "serde")]
82pub use shared::FileStorage;
83#[cfg(feature = "runtime")]
84pub use store::{
85    ChangeSet, ChangeSubscriber, ScopedChangeSubscriber, ScopedStore, StateSubscriber, Store,
86    StoreTask, StoreTaskError,
87};
88#[cfg(feature = "runtime")]
89pub use runtime::rw_store::{
90    ReadStore, RwChangeSubscriber, RwStateSubscriber, RwStore, ScopedRwStore,
91};
92#[cfg(all(feature = "runtime", feature = "arc-swap"))]
93pub use runtime::swap_store::{
94    ScopedSwapStore, SnapshotStore, SwapChangeSubscriber, SwapStateSubscriber, SwapStore,
95};
96pub use runtime::binding::{
97    ComposedBinding, ProjectedBinding, ReadProjectedBinding, ReadStateBinding,
98    RwProjectedBinding, RwStateBinding, StateBinding,
99};
100#[cfg(feature = "arc-swap")]
101pub use runtime::binding::{SnapshotProjectedBinding, SnapshotStateBinding};
102pub use sub::Sub;
103pub use test_runtime::TestRuntime;
104#[cfg(feature = "runtime")]
105pub use test_store::{ExhaustiveTestStore, TestStoreError};
106pub use test_support::{
107    allow_state_clones, on_state_clone, replay_snapshot, shared_get, shared_with_mut,
108};
109#[cfg(feature = "runtime")]
110pub use test_support::{
111    scoped_child_state, scoped_subscribe_state, scoped_subscriber_next, store_state,
112    subscribe_state, subscriber_wait_next,
113};
114
115pub use rust_key_paths;
116pub use key_paths_core;