Skip to main content

transition

Attribute Macro transition 

Source
#[transition]
Expand description

Validate and generate legal transitions for one source state.

Apply #[transition] to an impl Machine<CurrentState> block. Transition methods consume self and return Machine<NextState> or exact wrapper shapes around that same machine path such as ::core::result::Result<Machine<NextState>, E>, ::core::option::Option<Machine<NextState>>, or ::statum::Branch<Machine<Left>, Machine<Right>>. When the strict-introspection feature is enabled, transition graph semantics must be directly readable from that written return type or from a local #[introspect(return = ...)] escape hatch on the method.

Inside the impl, use:

  • self.transition() for unit target states
  • self.transition_with(data) for data-bearing target states
  • self.transition_map(|current| next_data) when the next payload is built from the current payload
use statum::{machine, state, transition};

#[state]
enum LightState {
    Off,
    On,
}

#[machine]
struct Light<LightState> {}

#[transition]
impl Light<Off> {
    fn switch_on(self) -> Light<On> {
        self.transition()
    }
}

fn main() {
    let _light = Light::<Off>::builder().build().switch_on();
}

Validate and generate legal transitions for one source state.

Apply #[transition] to an impl Machine<CurrentState> block. Each method must consume self and return a legal Machine<NextState> shape or a source-declared type alias that expands to that shape, or a supported wrapper around it, such as Result<Machine<NextState>, E>, Option<Machine<NextState>>, or statum::Branch<Machine<Left>, Machine<Right>>.

When the strict-introspection feature is enabled, transition graph semantics must be directly readable from the written return type or from a local #[introspect(return = ...)] escape hatch on the method.