Expand description
Determa State — a Rust implementation of the Determa State statechart engine.
Implements Determa State spec v0.0.5. Correctness is defined by the language-agnostic
conformance suite at https://github.com/fruwehq/determa-state-conformance (pinned at
tag v0.0.5). See SPEC.md in the spec repository for the normative text.
This crate exposes an embeddable library API (SPEC §2) and a standard determa-state //! CLI (src/bin/determa_state.rs, SPEC §13).
§Example
use determa_state::{build_machine, load_machines};
let docs = load_machines(include_str!("../examples/minimal.yaml"))
.expect("minimal.yaml parses");
let (valid, _errs) = determa_state::validate(&docs, &[]);
assert!(valid);
let _machine = build_machine(&docs[0]).expect("builds");Re-exports§
pub use loader::load_contract;pub use loader::load_machines;pub use loader::LoadError;pub use validate::validate;pub use validate::Contract;pub use machine::build as build_machine;pub use machine::resolve_definitions;pub use machine::Machine;pub use machine::NodeId;pub use machine::Scope;pub use runtime::Engine;pub use runtime::Mode;pub use runtime::RunResult;pub use runtime::Snapshot;pub use runtime::Status;pub use runtime::StepRecord;pub use value::Value;
Modules§
- cel
- Guard / action-value evaluation via the Common Expression Language
(SPEC §6), backed by the
cel-interpretercrate (cel-rust). - cli
- The standard
determa-stateCLI (SPEC §13). A thin wrapper over the libraryEnginethat persists state through a pluggable store (§13.1). Commands, exit codes, and the--jsonoutput shapes are normative. - export
- Mermaid
stateDiagram-v2export (SPEC §12). Renders the static structure of a machine; with astate_config, highlights the active leaves and their ancestors. - loader
- Loading Determa State YAML: multi-document machine files (§9: first doc is the root) and contract files (§7).
- machine
- The resolved machine: a flat state table (indexed by
NodeId) with alltransition_toreferences resolved toNodeIds, event scopes parsed, and actions/initials/choices expanded. Built once fromcrate::model::RawMachine. - model
- YAML machine-definition model (SPEC §4) and raw deserialization.
- runtime
- The Determa State runtime engine (SPEC §5). Run-to-completion dispatch over a resolved
Machine: hierarchical states with LCA exit/entry, esvs with scope, history, defer, timers over a virtual clock, orthogonal regions +done, choice pseudostates, active objects (spawn/publish/scope), faults, and snapshot/restore. - store
- Store backends (SPEC §8/§13.1). A store persists registered definition YAML
sources, instance snapshots, the virtual clock, and the processing mode. The
three standard backends —
file,mem,sqlite— are behaviorally identical. - validate
- Semantic validation (SPEC §5.5.1 choices, §7 contracts). Structural validation
(unknown fields, required fields) is enforced by serde’s
deny_unknown_fieldsduring loading; reference resolution happens incrate::machine::build. This module adds the checks the JSON schema cannot express. - value
- The dynamic value type used for esvs, event payloads, and CEL evaluation.