pub trait Transition<DestinationState>: Into<DestinationState> + State {
// Required method
fn guard(&self) -> TransitGuard;
// Provided method
fn action(&mut self) { ... }
}Expand description
Trait that must be implemented by a state that want to transition to DestinationState.
All states can have none or many transitions.
On top of the transition trait the state must implement the Into<DestinationState>
trait to specify what happens with the source state data while transitioning and how the
destination state is generated.
The action method is run once the transition executes.
The only non optional method is the guard function that specifies when the state transitions.
Required Methods§
Sourcefn guard(&self) -> TransitGuard
fn guard(&self) -> TransitGuard
Specifies when the state has to transit. Return TransitGuard::Remain to remain
in the current state and TransitGuard::Transit to transit into the next one.
This is the only function that must be implemented by the transition.
The others are optional and situational.
fn guard(&self) -> TransitGuard {
let foo = 0;
if foo == 0 {
TransitGuard::Remain
} else {
TransitGuard::Transit
}
}Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.