Skip to main content

EventRepository

Trait EventRepository 

Source
pub trait EventRepository<C, E, Version, Error> {
    // Required methods
    fn fetch_events(
        &self,
        command: &C,
    ) -> impl Future<Output = Result<Vec<(E, Version)>, Error>> + Send;
    fn save(
        &self,
        events: &[E],
    ) -> impl Future<Output = Result<Vec<(E, Version)>, Error>> + Send;
    fn version_provider(
        &self,
        event: &E,
    ) -> impl Future<Output = Result<Option<Version>, Error>> + Send;
}
Expand description

Event Repository trait

Generic parameters:

  • C - Command
  • E - Event
  • Version - Version/Offset/Sequence number
  • Error - Error

Required Methods§

Source

fn fetch_events( &self, command: &C, ) -> impl Future<Output = Result<Vec<(E, Version)>, Error>> + Send

Fetches current events, based on the command. Desugared async fn fetch_events(&self, command: &C) -> Result<Vec<(E, Version)>, Error>; to a normal fn that returns impl Future, and adds bound Send. You can freely move between the async fn and -> impl Future spelling in your traits and impls. This is true even when one form has a Send bound.

Source

fn save( &self, events: &[E], ) -> impl Future<Output = Result<Vec<(E, Version)>, Error>> + Send

Saves events. Desugared async fn save(&self, events: &[E], latest_version: &Option<Version>) -> Result<Vec<(E, Version)>, Error>; to a normal fn that returns impl Future, and adds bound Send You can freely move between the async fn and -> impl Future spelling in your traits and impls. This is true even when one form has a Send bound.

Source

fn version_provider( &self, event: &E, ) -> impl Future<Output = Result<Option<Version>, Error>> + Send

Version provider. It is used to provide the version/sequence of the stream to wich this event belongs to. Optimistic locking is useing this version to check if the event is already saved. Desugared async fn version_provider(&self, event: &E) -> Result<Option<Version>, Error>; to a normal fn that returns impl Future, and adds bound Send You can freely move between the async fn and -> impl Future spelling in your traits and impls. This is true even when one form has a Send bound.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<C, S, E, Repository, Decider, Version, Error> EventRepository<C, E, Version, Error> for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: EventRepository<C, E, Version, Error> + Sync, Decider: EventComputation<C, S, E, Error> + Sync, C: Sync, S: Sync, E: Sync, Version: Sync, Error: Sync,

Available on non-crate feature not-send-futures only.
Source§

impl<C, S, E, Repository, Version, Error> EventRepository<C, E, Version, Error> for EventSourcedOrchestratingAggregate<'_, C, S, E, Repository, Version, Error>
where Repository: EventRepository<C, E, Version, Error> + Sync, C: Sync, S: Sync, E: Sync, Version: Sync, Error: Sync,

Available on non-crate feature not-send-futures only.