pub trait State {
type Command;
type Event;
// Required methods
fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>);
fn evolve(&mut self, event: &Self::Event);
}Expand description
Required Associated Types§
Sourcetype Command
type Command
A command that relates to the state
Commands are processed by State::decide.
Sourcetype Event
type Event
An event that captures modifications to this state
Events are produced by State::decide and processed by
State::evolve.
Required Methods§
Sourcefn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>)
fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>)
Decide how to react to the provided command
If the command must result in changes to the state, any number of events that describe these state changes can be produced.
Sourcefn evolve(&mut self, event: &Self::Event)
fn evolve(&mut self, event: &Self::Event)
Evolve the state according to the provided event
This is the only method gets mutable access to the state, making sure that all changes to the state are captured as events.
Implementations of this method are supposed to be relatively dumb. Any
decisions that go into updating the state should be made in
State::decide, and encoded into the event.