Skip to main content

TransitionResult

Type Alias TransitionResult 

Source
pub type TransitionResult<Origin, Next, Error = Infallible> = Result<Next, ErrorState<Error, Origin, Next>>;
Expand description

The canonical return type of a state transition.

TransitionResult<Origin, Next, Error> is a type alias for Result<Next, ErrorState<Error, Origin, Next>> with Error defaulting to Infallible. It simplifies the signature of Transition::change and related methods by putting the three type parameters in a logical order: where we came from, where we’re going, and what can go wrong.

§Example


#[derive(Debug)]
struct Idle;
impl State for Idle {}

#[derive(Debug)]
struct Running;
impl State for Running {}

impl Transition<Running> for Idle {
    fn change(self, _ctx: &dyn Any) -> TransitionResult<Idle, Running> {
        Ok(Running)
    }
}

Aliased Type§

pub enum TransitionResult<Origin, Next, Error = Infallible> {
    Ok(Next),
    Err(ErrorState<Error, Origin, Next>),
}

Variants§

§1.0.0

Ok(Next)

Contains the success value

§1.0.0

Err(ErrorState<Error, Origin, Next>)

Contains the error value