use qubit_cas::FastCasError;
use thiserror::Error;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Error)]
pub enum FastStateMachineError {
#[error("unknown state: {state}")]
UnknownState {
state: usize,
},
#[error("unknown transition: {source_state} --{event}--> ?")]
UnknownTransition {
source_state: usize,
event: usize,
},
#[error("CAS transition failed after {attempts} attempt(s)")]
CasConflict {
attempts: u32,
},
}
pub type FastStateMachineResult = Result<usize, FastStateMachineError>;
#[doc(hidden)]
pub fn fast_state_machine_error_from_fast_cas_error(
error: FastCasError<FastStateMachineError>,
) -> FastStateMachineError {
match error {
FastCasError::Abort { error, .. } => error,
FastCasError::Conflict { attempts, .. } => FastStateMachineError::CasConflict { attempts },
}
}