pub struct MaterializedView<S, E, Repository, View, Error>
where Repository: ViewStateRepository<E, S, Error>, View: ViewStateComputation<E, S>,
{ /* private fields */ }
Expand description

Materialized View.

It is using a View / ViewStateComputation to compute new state based on the current state and the event. It is using a ViewStateRepository to fetch the current state and to save the new state.

Generic parameters:

  • S - State
  • E - Event
  • Repository - View State repository
  • View - View
  • Error - Error

Implementations§

source§

impl<S, E, Repository, View, Error> MaterializedView<S, E, Repository, View, Error>
where Repository: ViewStateRepository<E, S, Error> + Sync, View: ViewStateComputation<E, S> + Sync, E: Sync, S: Sync, Error: Sync,

source

pub fn new(repository: Repository, view: View) -> Self

Creates a new instance of MaterializedView.

source

pub async fn handle(&self, event: &E) -> Result<S, Error>

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

Trait Implementations§

source§

impl<S, E, Repository, View, Error> ViewStateComputation<E, S> for MaterializedView<S, E, Repository, View, Error>
where Repository: ViewStateRepository<E, S, Error>, View: ViewStateComputation<E, S>,

source§

fn compute_new_state(&self, current_state: Option<S>, events: &[&E]) -> S

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

source§

impl<S, E, Repository, View, Error> ViewStateRepository<E, S, Error> for MaterializedView<S, E, Repository, View, Error>
where Repository: ViewStateRepository<E, S, Error> + Sync, View: ViewStateComputation<E, S> + Sync, E: Sync, S: Sync, Error: Sync,

source§

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

Fetches current state, based on the event.

source§

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

Saves the new state.

Auto Trait Implementations§

§

impl<S, E, Repository, View, Error> RefUnwindSafe for MaterializedView<S, E, Repository, View, Error>
where E: RefUnwindSafe, Error: RefUnwindSafe, Repository: RefUnwindSafe, S: RefUnwindSafe, View: RefUnwindSafe,

§

impl<S, E, Repository, View, Error> Send for MaterializedView<S, E, Repository, View, Error>
where E: Send, Error: Send, Repository: Send, S: Send, View: Send,

§

impl<S, E, Repository, View, Error> Sync for MaterializedView<S, E, Repository, View, Error>
where E: Sync, Error: Sync, Repository: Sync, S: Sync, View: Sync,

§

impl<S, E, Repository, View, Error> Unpin for MaterializedView<S, E, Repository, View, Error>
where E: Unpin, Error: Unpin, Repository: Unpin, S: Unpin, View: Unpin,

§

impl<S, E, Repository, View, Error> UnwindSafe for MaterializedView<S, E, Repository, View, Error>
where E: UnwindSafe, Error: UnwindSafe, Repository: UnwindSafe, S: UnwindSafe, View: 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.