Skip to main content

Crate determa_state

Crate determa_state 

Source
Expand description

Determa State — a Rust implementation of the Determa State statechart engine.

Implements Determa State spec v0.0.6. Correctness is defined by the language-agnostic conformance suite at https://github.com/fruwehq/determa-state-conformance (pinned at tag v0.0.6). 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");

Machines can also be built in code from a native value (no YAML text), e.g. with the serde_json::json! macro:

use determa_state::{build_machine, load_machine_from_value};
use serde_json::json;
let raw = load_machine_from_value(json!({
    "id": "ping",
    "top": {"initial": {"transition_to": "up"}, "states": {"up": {}}}
})).expect("parses");
let _machine = build_machine(&raw).expect("builds");

Re-exports§

pub use loader::load_contract;
pub use loader::load_machine_from_value;
pub use loader::load_machines;
pub use loader::load_machines_from_values;
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-interpreter crate (cel-rust).
cli
The standard determa-state CLI (SPEC §13). A thin wrapper over the library Engine that persists state through a pluggable store (§13.1). Commands, exit codes, and the --json output shapes are normative.
export
Mermaid stateDiagram-v2 export (SPEC §12). Renders the static structure of a machine; with a state_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 all transition_to references resolved to NodeIds, event scopes parsed, and actions/initials/choices expanded. Built once from crate::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_fields during loading; reference resolution happens in crate::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.