Struct MaterializedView

Source
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§

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

Fetches current state, based on the event.

Source§

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

Saves the new state.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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