qubit-state-machine 0.2.3

A small, thread-safe finite state machine for Rust
Documentation
/*******************************************************************************
 *
 *    Copyright (c) 2026 Haixing Hu.
 *
 *    SPDX-License-Identifier: Apache-2.0
 *
 *    Licensed under the Apache License, Version 2.0.
 *
 ******************************************************************************/
//! # Qubit State Machine
//!
//! A small, thread-safe finite state machine for Rust.
//!
//! This crate is intentionally compact. It stores immutable transition rules
//! and applies events to an [`AtomicRef`] through a compare-and-swap executor.
//!
//! # Examples
//!
//! ```
//! use qubit_state_machine::{AtomicRef, StateMachine};
//!
//! #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
//! enum State {
//!     New,
//!     Running,
//!     Done,
//! }
//!
//! #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
//! enum Event {
//!     Start,
//!     Finish,
//! }
//!
//! let machine = StateMachine::builder()
//!     .add_states(&[State::New, State::Running, State::Done])
//!     .set_initial_state(State::New)
//!     .set_final_state(State::Done)
//!     .add_transition(State::New, Event::Start, State::Running)
//!     .add_transition(State::Running, Event::Finish, State::Done)
//!     .build()
//!     .expect("state machine should be valid");
//!
//! let state = AtomicRef::from_value(State::New);
//! assert_eq!(machine.trigger(&state, Event::Start).unwrap(), State::Running);
//! assert_eq!(*state.load(), State::Running);
//! ```
//!

#![deny(missing_docs)]

mod state_machine;
mod state_machine_build_error;
mod state_machine_builder;
mod state_machine_error;
mod transition;

pub use qubit_atomic::AtomicRef;
pub use state_machine::StateMachine;
pub use state_machine_build_error::StateMachineBuildError;
pub use state_machine_builder::StateMachineBuilder;
pub use state_machine_error::{StateMachineError, StateMachineResult};
pub use transition::Transition;