State

Trait State 

Source
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

Implemented for state that can be wrapped by a Service

See Service for a detailed explanation.

Required Associated Types§

Source

type Command

A command that relates to the state

Commands are processed by State::decide.

Source

type Event

An event that captures modifications to this state

Events are produced by State::decide and processed by State::evolve.

Required Methods§

Source

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.

Source

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.

Implementors§