Struct EventSourcedAggregate

Source
pub struct EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: EventRepository<C, E, Version, Error>, Decider: EventComputation<C, S, E, Error>,
{ /* 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, Error> + 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, Error> for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: EventRepository<C, E, Version, Error>, Decider: EventComputation<C, S, E, Error>,

Source§

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

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

Source§

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

Fetches current events, based on the command.

Source§

async fn save(&self, events: &[E]) -> Result<Vec<(E, Version)>, Error>

Saves events.

Source§

async fn version_provider(&self, event: &E) -> Result<Option<Version>, Error>

Version provider. It is used to provide the version/sequence of the event. Optimistic locking is useing this version to check if the event is already saved.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<C, S, E, Repository, Decider, Version, Error> UnwindSafe for EventSourcedAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: UnwindSafe, Decider: UnwindSafe, C: UnwindSafe, S: UnwindSafe, E: UnwindSafe, Version: UnwindSafe, Error: 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>,

Source§

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>,

Source§

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.