Trait aper::StateMachine
source · [−]pub trait StateMachine: Clone + DeserializeOwned + Serialize + Debug + 'static {
type Transition: Debug + Serialize + DeserializeOwned + Clone + PartialEq;
type Conflict: Debug + Serialize + DeserializeOwned + Clone + PartialEq;
fn apply(
&self,
transition: &Self::Transition
) -> Result<Self, Self::Conflict>;
}
Expand description
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.
Required Associated Types
sourcetype Transition: Debug + Serialize + DeserializeOwned + Clone + PartialEq
type Transition: Debug + Serialize + DeserializeOwned + Clone + PartialEq
The StateMachine::Transition
type associates another type with this state machine
as its transitions.
Required Methods
sourcefn apply(&self, transition: &Self::Transition) -> Result<Self, Self::Conflict>
fn apply(&self, transition: &Self::Transition) -> Result<Self, Self::Conflict>
Update the state machine according to the given [Transition
]. This method must be
deterministic: calling it on a clone of the state with a clone of the [Transition
]
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.