pub trait StateMachineImpl: 'static {
type Standin;
type Impl: StateMachineImpl<Standin = Self::Standin, Impl = Self::Impl>;
type TransitionToken;
}Expand description
Connects an implementation type to a state-machine definition.
Implementations are 'static so storage backends can provide borrowed
guard families without repeating the implementation type in the backend.
The associated Standin selects the definition-crate contract, while
TransitionToken is the private capability required to perform retagging.
crate::StateMachineImpl! generates this implementation and keeps the
transition capability’s construction private. Code outside the invocation
module cannot manufacture the token:
use magicstatemachines::{Initial, State, StateMachineImpl, States, StorageStateOwned, Transition};
mod implementation {
use super::*;
pub struct Standin;
pub struct Runtime;
States! {
Ready;
Running;
}
impl Initial<Ready> for Standin {}
impl Transition<Ready, Running> for Standin {}
magicstatemachines::StateMachineImpl!(Runtime: Standin; transition Ready => Running(););
pub fn ready() -> State<StorageStateOwned, Runtime, Ready> {
State::new(Runtime)
}
}
let ready = implementation::ready();
let _ = magicstatemachines::transition_state::<_, _, _, implementation::Running>(
ready,
implementation::__StateMachineTransitionToken(())
).call(());The generated ergonomic helpers are also private to the invocation module.
This means implementation methods can call transition!,
but external callers can only call the methods you expose:
use magicstatemachines::{Initial, State, States, StorageStateOwned, Transition};
mod implementation {
use super::*;
pub struct Standin;
pub struct Runtime;
States! {
Ready;
Running;
}
impl Initial<Ready> for Standin {}
impl Transition<Ready, Running> for Standin {}
magicstatemachines::StateMachineImpl!(Runtime: Standin; transition Ready => Running(););
pub fn ready() -> State<StorageStateOwned, Runtime, Ready> {
State::new(Runtime)
}
}
let ready = implementation::ready();
let _ = magicstatemachines::transition!(ready);Required Associated Types§
Sourcetype Impl: StateMachineImpl<Standin = Self::Standin, Impl = Self::Impl>
type Impl: StateMachineImpl<Standin = Self::Standin, Impl = Self::Impl>
Runtime implementation controlled by the state machine.
Sourcetype TransitionToken
type TransitionToken
Capability required to perform transitions.
Use crate::StateMachineImpl! to generate this capability and its
private ergonomic transition helpers.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T> StateMachineImpl for Box<T>where
T: StateMachineImpl + ?Sized,
Available on crate feature alloc only.
impl<T> StateMachineImpl for Box<T>where
T: StateMachineImpl + ?Sized,
alloc only.type Standin = <T as StateMachineImpl>::Standin
type Impl = <T as StateMachineImpl>::Impl
type TransitionToken = <T as StateMachineImpl>::TransitionToken
Source§impl<T> StateMachineImpl for Pin<Box<T>>where
T: StateMachineImpl + ?Sized,
Available on crate feature alloc only.
impl<T> StateMachineImpl for Pin<Box<T>>where
T: StateMachineImpl + ?Sized,
alloc only.