pub trait EventSourcedExt {
    async fn spawn<L, S, EvtToBytes, EvtToBytesError, StateToBytes, StateToBytesError, EvtFromBytes, EvtFromBytesError, StateFromBytes, StateFromBytesError>(
        self,
        id: Uuid,
        cmd_buffer: NonZeroUsize,
        evt_log: L,
        snapshot_store: S,
        binarizer: Binarizer<EvtToBytes, EvtFromBytes, StateToBytes, StateFromBytes>
    ) -> Result<EntityRef<Self>, SpawnError>
    where
        Self: EventSourced,
        L: EvtLog,
        S: SnapshotStore,
        EvtToBytes: Fn(&Self::Evt) -> Result<Bytes, EvtToBytesError> + Send + Sync + 'static,
        EvtToBytesError: StdError + Send + Sync + 'static,
        StateToBytes: Fn(&Self::State) -> Result<Bytes, StateToBytesError> + Send + Sync + 'static,
        StateToBytesError: StdError + Send + Sync + 'static,
        EvtFromBytes: Fn(Bytes) -> Result<Self::Evt, EvtFromBytesError> + Copy + Send + Sync + 'static,
        EvtFromBytesError: StdError + Send + Sync + 'static,
        StateFromBytes: Fn(Bytes) -> Result<Self::State, StateFromBytesError> + Copy + Send + Sync + 'static,
        StateFromBytesError: StdError + Send + Sync + 'static
, { ... } }
Expand description

Extension methods for types implementing EventSourced.

Provided Methods§

source

async fn spawn<L, S, EvtToBytes, EvtToBytesError, StateToBytes, StateToBytesError, EvtFromBytes, EvtFromBytesError, StateFromBytes, StateFromBytesError>(
    self,
    id: Uuid,
    cmd_buffer: NonZeroUsize,
    evt_log: L,
    snapshot_store: S,
    binarizer: Binarizer<EvtToBytes, EvtFromBytes, StateToBytes, StateFromBytes>
) -> Result<EntityRef<Self>, SpawnError>where
    Self: EventSourced,
    L: EvtLog,
    S: SnapshotStore,
    EvtToBytes: Fn(&Self::Evt) -> Result<Bytes, EvtToBytesError> + Send + Sync + 'static,
    EvtToBytesError: StdError + Send + Sync + 'static,
    StateToBytes: Fn(&Self::State) -> Result<Bytes, StateToBytesError> + Send + Sync + 'static,
    StateToBytesError: StdError + Send + Sync + 'static,
    EvtFromBytes: Fn(Bytes) -> Result<Self::Evt, EvtFromBytesError> + Copy + Send + Sync + 'static,
    EvtFromBytesError: StdError + Send + Sync + 'static,
    StateFromBytes: Fn(Bytes) -> Result<Self::State, StateFromBytesError> + Copy + Send + Sync + 'static,
    StateFromBytesError: StdError + Send + Sync + 'static,

Spawns an entity implementing EventSourced with the given ID and creates an EntityRef as a handle for it.

First the given SnapshotStore is used to find and possibly load a snapshot. Then the EvtLog is used to find the last sequence number and then to load any remaining events.

Commands can be passed to the spawned entity by invoking handle_cmd on the returned EntityRef which uses a buffered channel with the given size.

Commands are handled by the command handler of this entity. They can be rejected by returning an error. Valid commands may produce an event which get persisted to the EvtLog along with an increasing sequence number and then applied to the event handler of this entity. The event handler may decide to save a snapshot at the current sequence number which is used to speed up future spawning.

Implementors§

source§

impl<E> EventSourcedExt for Ewhere
    E: EventSourced,