pub trait StateProgram:
Aper<Intent = IntentEvent<Self::T>>
+ Send
+ Sync
+ 'static{
type T: Serialize + DeserializeOwned + Clone + PartialEq;
// Required method
fn new() -> Self;
// Provided method
fn suspended_event(&self) -> Option<IntentEvent<Self::T>> { ... }
}Expand description
This trait can be added to a [StateMachine] which takes a [TransitionEvent] as its transition. Only state machines with this trait can be used directly with the aper client/server infrastructure.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn suspended_event(&self) -> Option<IntentEvent<Self::T>>
fn suspended_event(&self) -> Option<IntentEvent<Self::T>>
A state machine may “suspend” an event which occurs at a specific time in the future. This is useful for ensuring that the state is updated at a future time regardless of a user-initiated state change before then. State machines that only change state as a result of user-initiated events can ignore this method, as the default implementation is to never suspend an event.
This method is called by the server once after every call to process_event. If it
returns None, no event is suspended, and any previously suspended event is canceled.
If it returns Some, the provided event becomes the “suspended” event, replacing the
prior suspended event if there was one.
Only one event can be suspended at a time. If a state machine wants to be triggered for multiple events in the future, it is up to that state machine to return the (chronologically) next event each time this method is called.
Currently, only the state machine running on the server ever has this method called.
Since they are not associated with a particular player, suspended events trigger
process_event with a None as the player in the [TransitionEvent].
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.