Skip to main content

Projection

Trait Projection 

Source
pub trait Projection: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn handles(&self) -> Vec<String>;
    fn handle<'life0, 'life1, 'async_trait>(
        &'life0 self,
        event: &'life1 Event,
    ) -> Pin<Box<dyn Future<Output = ProjectionResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ProjectionResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn rebuild<'life0, 'async_trait>(
        &'life0 self,
        events: Vec<Event>,
    ) -> Pin<Box<dyn Future<Output = ProjectionResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

A projection is the composed unit of a projector + its read model store.

It represents a complete, self-contained read model: the logic that transforms events into state, paired with the storage where that state lives.

Most users don’t implement this trait directly. Instead, implement Projector and compose it with a ReadModelStore via ProjectionUnit.

§&self not &mut self

All methods take &self. Mutable state lives in the ReadModelStore, which handles interior mutability via connection pools, Mutex, etc.

Required Methods§

Source

fn name(&self) -> &str

Projection name (delegates to the projector).

Source

fn handles(&self) -> Vec<String>

Event types this projection handles (delegates to the projector).

Source

fn handle<'life0, 'life1, 'async_trait>( &'life0 self, event: &'life1 Event, ) -> Pin<Box<dyn Future<Output = ProjectionResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Handle a single event by applying it through the projector to the store.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ProjectionResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear all read model state for this projection.

Provided Methods§

Source

fn rebuild<'life0, 'async_trait>( &'life0 self, events: Vec<Event>, ) -> Pin<Box<dyn Future<Output = ProjectionResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Rebuild from a set of events: clear, then replay matching events.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§