pub trait Projection {
// Required methods
fn name(&self) -> &'static str;
fn handle_event(&mut self, envelope: &EventEnvelope);
// Provided method
fn last_sequence(&self) -> Option<u64> { ... }
}Expand description
A read-model builder that consumes events and maintains queryable state.
§Contract
handle_eventis called for every event in stream order.handle_eventmust not panic on events it doesn’t recognise (forward compatibility: new event types appear when new domain features are deployed before all projections are updated).- The projection is rebuilt from scratch by replaying all events through
ProjectionRunner::run; implementations must tolerate this.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
A stable human-readable name for this projection (used in logs/metrics).
Sourcefn handle_event(&mut self, envelope: &EventEnvelope)
fn handle_event(&mut self, envelope: &EventEnvelope)
Process a single event, updating internal read-model state.
Provided Methods§
Sourcefn last_sequence(&self) -> Option<u64>
fn last_sequence(&self) -> Option<u64>
The sequence number of the last event this projection processed.
Return None when the projection has not processed any events yet
(i.e. it needs a full replay).
Implement this method if your projection stores the cursor alongside
the read model so ProjectionRunner::catch_up can perform
incremental updates.
Defaults to None.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".