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`, optics, panic recovery |
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, reduce_panic, 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 {
43    pub use key_paths_core::{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 reduce_panic::{catch_reduce, catch_reduce_panic, ReducePanic};
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};
74pub use scope::{
75    lift_cmd, lift_cmd_with_id, ForEachReducer, IfCaseLetReducer, IfLetReducer, OptionalReducer,
76    ScopeReducer,
77};
78pub use shared::{InMemoryStorage, Shared, SharedSubscriber, Storage, StorageError};
79#[cfg(feature = "serde")]
80pub use shared::FileStorage;
81#[cfg(feature = "runtime")]
82pub use store::{
83    ScopedStore, StateSubscriber, Store, StoreTask, StoreTaskError,
84};
85pub use sub::Sub;
86pub use test_runtime::TestRuntime;
87#[cfg(feature = "runtime")]
88pub use test_store::{ExhaustiveTestStore, TestStoreError};
89pub use test_support::{
90    allow_state_clones, on_state_clone, replay_snapshot, shared_get, shared_with_mut,
91};
92#[cfg(feature = "runtime")]
93pub use test_support::{
94    scoped_child_state, scoped_subscribe_state, scoped_subscriber_next, store_state,
95    subscribe_state, subscriber_wait_next,
96};
97
98pub use rust_key_paths;
99pub use key_paths_core;