pub trait EventSourced: Sized + Send + Sync + 'static {
    type Cmd: Debug + Send + Sync + 'static;
    type Evt: Debug + Send + Sync + 'static;
    type State: Send + Sync;
    type Error: StdError + Send + Sync + 'static;

    fn handle_cmd(
        &self,
        cmd: Self::Cmd
    ) -> Result<impl IntoTaggedEvt<Self::Evt>, Self::Error>; fn handle_evt(&mut self, evt: Self::Evt) -> Option<Self::State>; fn set_state(&mut self, state: Self::State); }
Expand description

Command and event handling for an event sourced entity.

Required Associated Types§

source

type Cmd: Debug + Send + Sync + 'static

Command type.

source

type Evt: Debug + Send + Sync + 'static

Event type.

source

type State: Send + Sync

Snapshot state type.

source

type Error: StdError + Send + Sync + 'static

Error type for rejected (a.k.a. invalid) commands.

Required Methods§

source

fn handle_cmd(
    &self,
    cmd: Self::Cmd
) -> Result<impl IntoTaggedEvt<Self::Evt>, Self::Error>

Command handler, returning the to be persisted event or an error.

source

fn handle_evt(&mut self, evt: Self::Evt) -> Option<Self::State>

Event handler, returning whether to take a snapshot or not.

source

fn set_state(&mut self, state: Self::State)

Snapshot state handler.

Implementors§