Trait eventsourced::EventSourcedExt
source · pub trait EventSourcedExt: Sized {
// Provided method
async fn spawn<L, S, EvtToBytes, EvtToBytesError, StateToBytes, StateToBytesError, EvtFromBytes, EvtFromBytesError, StateFromBytes, StateFromBytesError>(
id: Self::Id,
snapshot_after: Option<NonZeroU64>,
cmd_buffer: NonZeroUsize,
evt_log: L,
snapshot_store: S,
binarizer: Binarizer<EvtToBytes, EvtFromBytes, StateToBytes, StateFromBytes>
) -> Result<EntityRef<Self>, SpawnError>
where Self: EventSourced,
L: EvtLog<Id = Self::Id>,
S: SnapshotStore<Id = Self::Id>,
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§
sourceasync fn spawn<L, S, EvtToBytes, EvtToBytesError, StateToBytes, StateToBytesError, EvtFromBytes, EvtFromBytesError, StateFromBytes, StateFromBytesError>(
id: Self::Id,
snapshot_after: Option<NonZeroU64>,
cmd_buffer: NonZeroUsize,
evt_log: L,
snapshot_store: S,
binarizer: Binarizer<EvtToBytes, EvtFromBytes, StateToBytes, StateFromBytes>
) -> Result<EntityRef<Self>, SpawnError>where
Self: EventSourced,
L: EvtLog<Id = Self::Id>,
S: SnapshotStore<Id = Self::Id>,
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,
async fn spawn<L, S, EvtToBytes, EvtToBytesError, StateToBytes, StateToBytesError, EvtFromBytes, EvtFromBytesError, StateFromBytes, StateFromBytesError>(
id: Self::Id,
snapshot_after: Option<NonZeroU64>,
cmd_buffer: NonZeroUsize,
evt_log: L,
snapshot_store: S,
binarizer: Binarizer<EvtToBytes, EvtFromBytes, StateToBytes, StateFromBytes>
) -> Result<EntityRef<Self>, SpawnError>where
Self: EventSourced,
L: EvtLog<Id = Self::Id>,
S: SnapshotStore<Id = Self::Id>,
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 event sourced entity 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 the spawned entity. They can be rejected by returning an error. Valid commands produce an event with an optional tag which gets persisted to the EvtLog and then applied to the event handler of the respective entity. The event handler may decide to save a snapshot which is used to speed up future spawning.