pub struct Projection<E: Executor, P: Default + 'static> { /* private fields */ }Expand description
Projection for loading aggregate state from events.
Combines event handlers to rebuild aggregate state by replaying events. Supports snapshots for performance optimization.
§Example
let result = Projection::<_, AccountView>::new::<Account>("account-123")
.handler(account_opened)
.handler(money_deposited)
.data(app_config)
.execute(&executor)
.await?;Implementations§
Source§impl<E: Executor, P: Snapshot<E> + Default + 'static> Projection<E, P>
impl<E: Executor, P: Snapshot<E> + Default + 'static> Projection<E, P>
Sourcepub fn new<A: Aggregator>(id: impl Into<String>) -> Projection<E, P>
pub fn new<A: Aggregator>(id: impl Into<String>) -> Projection<E, P>
Creates a builder for loading aggregate state.
This consumes the projection and returns a [LoadBuilder] configured
to load the state for the specified aggregate.
§Type Parameters
A: The aggregate type to load
Sourcepub fn ids<A: Aggregator>(ids: Vec<impl Into<String>>) -> Projection<E, P>
pub fn ids<A: Aggregator>(ids: Vec<impl Into<String>>) -> Projection<E, P>
Creates a builder for loading aggregate state.
This consumes the projection and returns a [LoadBuilder] configured
to load the state for the specified aggregate.
§Type Parameters
A: The aggregate type to load
Sourcepub fn revision(self, value: u16) -> Self
pub fn revision(self, value: u16) -> Self
Sets the snapshot revision.
Changing the revision invalidates existing snapshots, forcing a full rebuild.
Sourcepub fn safety_check(self) -> Self
pub fn safety_check(self) -> Self
Enables safety checks for unhandled events.
When enabled, execution fails if an event is encountered without a handler.
Sourcepub fn handler<H: Handler<P> + 'static>(self, h: H) -> Self
pub fn handler<H: Handler<P> + 'static>(self, h: H) -> Self
Registers an event handler with this projection.
§Panics
Panics if a handler for the same event type is already registered.
Sourcepub fn skip<EV: AggregatorEvent + Send + Sync + 'static>(self) -> Self
pub fn skip<EV: AggregatorEvent + Send + Sync + 'static>(self) -> Self
Registers a skip handler with this projection.
§Panics
Panics if a handler for the same event type is already registered.
Sourcepub fn data<D: Send + Sync + 'static>(self, v: D) -> Self
pub fn data<D: Send + Sync + 'static>(self, v: D) -> Self
Adds shared data to the load context.
Data added here is accessible in handlers via the context.
Sourcepub fn aggregator<A: Aggregator>(self, id: impl Into<String>) -> Self
pub fn aggregator<A: Aggregator>(self, id: impl Into<String>) -> Self
Adds a related aggregate to load events from.
Use this when the projection needs events from multiple aggregates.