pub struct StateTransitionError<S> {
pub from: S,
pub to: S,
}Expand description
Error indicating an invalid state transition.
The type parameter S is the status enum (e.g. OrderStatus, ReturnStatus).
This keeps transition errors strongly-typed while reusing a single generic
error structure across all domain state machines.
§Example
use stateset_core::errors::StateTransitionError;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Light { Red, Yellow, Green }
impl std::fmt::Display for Light {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
let err = StateTransitionError::new(Light::Red, Light::Green);
assert_eq!(err.to_string(), "invalid state transition from Red to Green");
assert_eq!(err.from, Light::Red);
assert_eq!(err.to, Light::Green);Fields§
§from: SThe current state.
to: SThe requested (invalid) target state.
Implementations§
Source§impl<S> StateTransitionError<S>
impl<S> StateTransitionError<S>
Trait Implementations§
Source§impl<S: Clone> Clone for StateTransitionError<S>
impl<S: Clone> Clone for StateTransitionError<S>
Source§fn clone(&self) -> StateTransitionError<S>
fn clone(&self) -> StateTransitionError<S>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<S: Copy> Copy for StateTransitionError<S>
Source§impl<S: Debug> Debug for StateTransitionError<S>
impl<S: Debug> Debug for StateTransitionError<S>
Source§impl<S: Display> Display for StateTransitionError<S>
impl<S: Display> Display for StateTransitionError<S>
impl<S: Eq> Eq for StateTransitionError<S>
Source§impl<S: Debug + Display> Error for StateTransitionError<S>
impl<S: Debug + Display> Error for StateTransitionError<S>
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl<S: Hash> Hash for StateTransitionError<S>
impl<S: Hash> Hash for StateTransitionError<S>
Source§impl<S: PartialEq> PartialEq for StateTransitionError<S>
impl<S: PartialEq> PartialEq for StateTransitionError<S>
impl<S: PartialEq> StructuralPartialEq for StateTransitionError<S>
Auto Trait Implementations§
impl<S> Freeze for StateTransitionError<S>where
S: Freeze,
impl<S> RefUnwindSafe for StateTransitionError<S>where
S: RefUnwindSafe,
impl<S> Send for StateTransitionError<S>where
S: Send,
impl<S> Sync for StateTransitionError<S>where
S: Sync,
impl<S> Unpin for StateTransitionError<S>where
S: Unpin,
impl<S> UnsafeUnpin for StateTransitionError<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for StateTransitionError<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more