pub struct StateStoredAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: StateRepository<C, S, Version, Error>, Decider: StateComputation<C, S, E>,
{ /* private fields */ }
Expand description

State Stored Aggregate.

It is using a Decider / StateComputation to compute new state based on the current state and the command. It is using a StateRepository to fetch the current state and to save the new state.

Generic parameters:

  • C - Command
  • S - State
  • E - Event
  • Repository - State repository
  • Decider - State computation
  • Version - Version
  • Error - Error

Implementations§

source§

impl<C, S, E, Repository, Decider, Version, Error> StateStoredAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: StateRepository<C, S, Version, Error> + Sync, Decider: StateComputation<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 StateStoredAggregate.

source

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

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

Trait Implementations§

source§

impl<C, S, E, Repository, Decider, Version, Error> StateComputation<C, S, E> for StateStoredAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: StateRepository<C, S, Version, Error>, Decider: StateComputation<C, S, E>,

source§

fn compute_new_state(&self, current_state: Option<S>, command: &C) -> S

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

source§

impl<C, S, E, Repository, Decider, Version, Error> StateRepository<C, S, Version, Error> for StateStoredAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: StateRepository<C, S, Version, Error> + Sync, Decider: StateComputation<C, S, E> + Sync, C: Sync, S: Sync, E: Sync, Version: Sync, Error: Sync,

source§

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

Fetches current state, based on the command.

source§

fn save<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, state: &'life1 S, version: &'life2 Option<Version> ) -> Pin<Box<dyn Future<Output = Result<(S, Version), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Saves state.

Auto Trait Implementations§

§

impl<C, S, E, Repository, Decider, Version, Error> RefUnwindSafe for StateStoredAggregate<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 StateStoredAggregate<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 StateStoredAggregate<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 StateStoredAggregate<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 StateStoredAggregate<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.