Skip to main content

qubit_state_machine/fast/
fast_state_machine_error.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10
11//! Runtime errors returned by `FastStateMachine` transitions.
12
13use thiserror::Error;
14
15/// Error returned when applying an event through a [`crate::FastStateMachine`].
16#[derive(Debug, Clone, Copy, Eq, PartialEq, Error)]
17pub enum FastStateMachineError {
18    /// The current state code is not configured in the state machine.
19    #[error("unknown state: {state}")]
20    UnknownState {
21        /// The unregistered current state code.
22        state: usize,
23    },
24
25    /// No transition is configured for the `(state, event)` pair.
26    #[error("unknown transition: {source_state} --{event}--> ?")]
27    UnknownTransition {
28        /// The source state code.
29        source_state: usize,
30
31        /// The triggering event code.
32        event: usize,
33    },
34
35    /// CAS conflicts were exhausted before the update could be installed.
36    #[error("CAS transition failed after {attempts} attempt(s)")]
37    CasConflict {
38        /// The total number of CAS attempts executed.
39        attempts: u32,
40    },
41}
42
43/// Result returned by `FastStateMachine` runtime transition APIs.
44pub type FastStateMachineResult = Result<usize, FastStateMachineError>;