use core::error;
use core::fmt;
use crate::Events;
use crate::States;
#[derive(Debug)]
pub enum ValidationError<S, E> {
InvalidStateIndex { expected: usize, got: usize },
InvalidEventIndex { expected: usize, got: usize },
NoInitialState,
UndefinedTransition { from: S, event: E },
}
impl<S: States + fmt::Debug, E: Events + fmt::Debug> fmt::Display for ValidationError<S, E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidStateIndex { expected, got } => {
write!(f, "Invalid state index! Expected {expected}, got {got}")
}
Self::InvalidEventIndex { expected, got } => {
write!(f, "Invalid event index! Expected {expected}, got {got}")
}
Self::NoInitialState => {
write!(f, "The initial state is not set!")
}
Self::UndefinedTransition { from, event } => write!(
f,
"There is no transition that goes from state '{from:?}' on event '{event:?}'"
),
}
}
}
impl<S: States + fmt::Debug, E: Events + fmt::Debug> error::Error for ValidationError<S, E> {}