Struct StateStoredAggregate

Source
pub struct StateStoredAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: StateRepository<C, S, Version, Error>, Decider: StateComputation<C, S, E, Error>,
{ /* 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, 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 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, Error> for StateStoredAggregate<C, S, E, Repository, Decider, Version, Error>
where Repository: StateRepository<C, S, Version, Error>, Decider: StateComputation<C, S, E, Error>,

Source§

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

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

Source§

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

Fetches current state, based on the command.

Source§

async fn save( &self, state: &S, version: &Option<Version>, ) -> Result<(S, Version), Error>

Saves state.

Auto Trait Implementations§

§

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

§

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