Skip to main content

Projection

Trait Projection 

Source
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_event is called for every event in stream order.
  • handle_event must 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§

Source

fn name(&self) -> &'static str

A stable human-readable name for this projection (used in logs/metrics).

Source

fn handle_event(&mut self, envelope: &EventEnvelope)

Process a single event, updating internal read-model state.

Provided Methods§

Source

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".

Implementors§