Expand description
Mindset: A pure functional state machine library
Mindset is built on Stillwater’s “pure core, imperative shell” philosophy. The core state machine logic is composed of pure functions with no side effects, while effects are isolated in Effect monads using Stillwater 0.11.0.
§Core Concepts
- State: Type-safe state representation via the
Statetrait - Guards: Pure predicate functions that control transitions
- History: Immutable tracking of state transitions over time
- Effects: Effectful state transitions using Stillwater’s zero-cost effect system
§Example
use mindset::core::{State, StateHistory, StateTransition};
use mindset::effects::{StateMachine, Transition, TransitionResult};
use serde::{Deserialize, Serialize};
use chrono::Utc;
use stillwater::prelude::*;
use std::sync::Arc;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
enum WorkflowState {
Initial,
Processing,
Complete,
}
impl State for WorkflowState {
fn name(&self) -> &str {
match self {
Self::Initial => "Initial",
Self::Processing => "Processing",
Self::Complete => "Complete",
}
}
fn is_final(&self) -> bool {
matches!(self, Self::Complete)
}
}
// Create a state machine with effectful transitions
let mut machine: StateMachine<WorkflowState, ()> = StateMachine::new(WorkflowState::Initial);
// Add a transition with an action factory
machine.add_transition(Transition {
from: WorkflowState::Initial,
to: WorkflowState::Processing,
guard: None,
action: Arc::new(|| pure(TransitionResult::Success(WorkflowState::Processing)).boxed()),
});Re-exports§
pub use builder::BuildError;pub use builder::StateMachineBuilder;pub use builder::TransitionBuilder;pub use checkpoint::Checkpoint;pub use checkpoint::CheckpointError;pub use checkpoint::MachineMetadata;pub use checkpoint::CHECKPOINT_VERSION;pub use core::Guard;pub use core::State;pub use core::StateHistory;pub use core::StateTransition;pub use effects::StateMachine;pub use effects::StepResult;pub use effects::Transition;pub use effects::TransitionError;pub use effects::TransitionResult;
Modules§
- builder
- Builder API for ergonomic state machine construction.
- checkpoint
- Checkpoint and resume functionality for state machines.
- core
- Core state machine types and logic.
- effects
- Effectful state machine operations using Stillwater 0.11.0.
Macros§
- state_
enum - Generate State trait implementation for simple enums.