Trait aper::StateMachine[][src]

pub trait StateMachine: Sized + Unpin + 'static + Send + Clone + Serialize + for<'d> Deserialize<'d> {
    type Transition: Sized + Unpin + 'static + Send + PartialEq + Clone + Serialize + for<'d> Deserialize<'d>;
    fn process_event(
        &mut self,
        transition_event: TransitionEvent<Self::Transition>
    ); fn suspended_event(&self) -> Option<SuspendedEvent<Self::Transition>> { ... } }

This trait provides the methods that Aper needs to be able to interact with an object as a state machine.

None of the methods in this trait provide access to the internal data of the state machine. It's up to you to implement accessor methods (or use public fields) in order to expose the data necessary to render your views.

Associated Types

type Transition: Sized + Unpin + 'static + Send + PartialEq + Clone + Serialize + for<'d> Deserialize<'d>[src]

The StateMachine::Transition type associates another type with this state machine as its transitions.

Loading content...

Required methods

fn process_event(&mut self, transition_event: TransitionEvent<Self::Transition>)[src]

Update the state machine according to the given TransitionEvent. This method must be deterministic: calling it on a clone of the state with a clone of the TransitionEvent must result in the same state, even at a different time and on a different machine. This is the requirement that allows Aper to keep the state in sync across multiple machines.

Loading content...

Provided methods

fn suspended_event(&self) -> Option<SuspendedEvent<Self::Transition>>[src]

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 cancelled. 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.

Loading content...

Implementors

Loading content...