pub struct EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: EventRepository<C, E, Version, Error>, Decider: EventComputation<C, S, E>,
{ /* private fields */ }
Expand description

Event Sourced Aggregate.

It is using a Decider / EventComputation to compute new events based on the current events and the command. It is using a EventRepository to fetch the current events and to save the new events.

Generic parameters:

  • C - Command
  • S - State
  • E - Event
  • Repository - Event repository
  • Decider - Event computation
  • Version - Version/Offset/Sequence number
  • Error - Error

Implementations§

source§

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

source

pub fn new(repository: Repository, decider: Decider) -> Self

Creates a new instance of EventSourcedAggregate.

source

pub async fn handle(&self, command: &C) -> Result<Vec<(E, Version)>, Error>

Handles the command by fetching the events from the repository, computing new events based on the current events and the command, and saving the new events to the repository.

Trait Implementations§

source§

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

source§

fn compute_new_events(&self, current_events: &[E], command: &C) -> Vec<E>

Computes new events based on the current events and the command.

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> + Sync, C: Sync, S: Sync, E: Sync, Version: Sync, Error: Sync,

source§

fn fetch_events<'life0, 'life1, 'async_trait>( &'life0 self, command: &'life1 C ) -> Pin<Box<dyn Future<Output = Result<Vec<(E, Version)>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetches current events, based on the command.

source§

fn save<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, events: &'life1 [E], latest_version: &'life2 Option<Version> ) -> Pin<Box<dyn Future<Output = Result<Vec<(E, Version)>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Saves events.

Auto Trait Implementations§

§

impl<C, S, E, Repository, Decider, Version, Error> RefUnwindSafe for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where C: RefUnwindSafe, Decider: RefUnwindSafe, E: RefUnwindSafe, Error: RefUnwindSafe, Repository: RefUnwindSafe, S: RefUnwindSafe, Version: RefUnwindSafe,

§

impl<C, S, E, Repository, Decider, Version, Error> Send for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where C: Send, Decider: Send, E: Send, Error: Send, Repository: Send, S: Send, Version: Send,

§

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

§

impl<C, S, E, Repository, Decider, Version, Error> Unpin for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where C: Unpin, Decider: Unpin, E: Unpin, Error: Unpin, Repository: Unpin, S: Unpin, Version: Unpin,

§

impl<C, S, E, Repository, Decider, Version, Error> UnwindSafe for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where C: UnwindSafe, Decider: UnwindSafe, E: UnwindSafe, Error: UnwindSafe, Repository: UnwindSafe, S: UnwindSafe, Version: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.