Skip to main content

Projection

Trait Projection 

Source
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§

Source

fn observes(&self) -> &[TypeCode]

TypeCodes this projection observes — the router filters incoming events against this slice.

Source

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:

  1. Update their internal view state.
  2. Bump last_applied to the event’s (sequence, tick).
Source

fn last_applied(&self) -> Option<(u64, Tick)>

Last (sequence, tick) applied — None if the projection is fresh.

Provided Methods§

Source

fn on_state_change( &mut self, _new_state: ObserverState, ) -> Result<(), ProjectionError>

React to a worker-state transition (Passive ↔ Active ↔ Draining). Default is no-op.

Implementors§