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§
Sourcefn handles(&self) -> Vec<String>
fn handles(&self) -> Vec<String>
Event types this projection handles (delegates to the projector).
Sourcefn 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 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.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".