statum 0.6.2

Represent workflow and protocol state correctly in Rust by making invalid states unrepresentable
Documentation

statum

statum is about representational correctness for workflow and protocol state. It helps make invalid, undesirable, or not-yet-validated states impossible to represent as ordinary values.

It applies the same idea as Option and Result: absence or failure becomes explicit in the type instead of staying implicit in the program.

This crate re-exports:

  • attribute macros: #[state], #[machine], #[transition], #[validators]
  • runtime types: statum::Error, statum::Result<T>
  • advanced traits: StateMarker, UnitState, DataState, CanTransition*
  • projection helpers: statum::projection

Install

[dependencies]
statum = "0.6.2"

Statum targets stable Rust and currently supports Rust 1.93+.

Mental Model

  • #[state] defines the legal phases
  • #[machine] defines the durable context
  • #[transition] defines the legal edges
  • #[validators] rebuilds typed machines from stored data

Minimal Example

use statum::{machine, state, transition};

#[state]
enum LightState {
    Off,
    On,
}

#[machine]
struct Light<LightState> {
    name: String,
}

#[transition]
impl Light<Off> {
    fn switch_on(self) -> Light<On> {
        self.transition()
    }
}

#[transition]
impl Light<On> {
    fn switch_off(self) -> Light<Off> {
        self.transition()
    }
}

Docs