pub trait Projection: Send + Sync {
// Required methods
fn observes(&self) -> &[TypeCode];
fn on_event(
&mut self,
event: &EventRecord,
ctx: &ProjectionContext<'_>,
) -> Result<(), ProjectionError>;
fn last_applied(&self) -> Option<(u64, Tick)>;
// Provided method
fn on_state_change(
&mut self,
_new_state: ObserverState,
) -> Result<(), ProjectionError> { ... }
}Expand description
L2 projection worker. Each implementor owns a read-model view that is
kept in sync with the L1 event stream for a specific set of TypeCodes.
Implementors must be Send + Sync so the ProjectionRouter can run
across worker threads; dedup / gap detection is centralised in the
router using Projection::last_applied.
Required Methods§
Sourcefn observes(&self) -> &[TypeCode]
fn observes(&self) -> &[TypeCode]
TypeCodes this projection observes — the router filters incoming events against this slice.
Sourcefn on_event(
&mut self,
event: &EventRecord,
ctx: &ProjectionContext<'_>,
) -> Result<(), ProjectionError>
fn on_event( &mut self, event: &EventRecord, ctx: &ProjectionContext<'_>, ) -> Result<(), ProjectionError>
Apply an event. Called only after router-side dedup + gap checks have succeeded. Implementations must:
- Update their internal view state.
- Bump
last_appliedto the event’s(sequence, tick).
Sourcefn last_applied(&self) -> Option<(u64, Tick)>
fn last_applied(&self) -> Option<(u64, Tick)>
Last (sequence, tick) applied — None if the projection is fresh.
Provided Methods§
Sourcefn on_state_change(
&mut self,
_new_state: ObserverState,
) -> Result<(), ProjectionError>
fn on_state_change( &mut self, _new_state: ObserverState, ) -> Result<(), ProjectionError>
React to a worker-state transition (Passive ↔ Active ↔ Draining). Default is no-op.