Skip to main content

Reader

Trait Reader 

Source
pub trait Reader: Send + 'static {
    type Event: Send + Clone + 'static;
    type Projection: Default + Send + Sync + 'static;
    type Error: Error + Send + 'static;

    // Required methods
    fn name(&self) -> &str;
    fn decode(bytes: &[u8]) -> Result<Self::Event, String>;
    fn apply<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        projection: &'life1 mut Self::Projection,
        event: Self::Event,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn tag(&self) -> Option<String> { ... }
    fn filter(&self) -> ReaderFilter { ... }
}
Expand description

Fold journal events into a projection.

The runner polls the configured read journal, decodes each atomr_persistence_query::EventEnvelope’s payload into Self::Event via Reader::decode, optionally filters by Reader::tag, and calls Reader::apply per event. Per-pid offsets are tracked internally so each event is applied exactly once per process lifetime.

Required Associated Types§

Source

type Event: Send + Clone + 'static

The event type this reader projects. Must match the aggregate’s event type when wired into a super::CqrsPattern.

Source

type Projection: Default + Send + Sync + 'static

The read-model state this reader builds.

Source

type Error: Error + Send + 'static

Domain error type for projection failures. Failures are logged at warn level; the runner advances past the offending event so it doesn’t get stuck.

Required Methods§

Source

fn name(&self) -> &str

Stable name of this reader. Used for tracing spans and dashboard child-actor naming. Must be unique per CQRS instance.

Source

fn decode(bytes: &[u8]) -> Result<Self::Event, String>

Decode a journal payload back into the event type. The codec must be the inverse of the aggregate’s encode_event. Used as the fallback when no crate::cqrs::EventCodecRegistry is configured for the relevant manifest.

Source

fn apply<'life0, 'life1, 'async_trait>( &'life0 mut self, projection: &'life1 mut Self::Projection, event: Self::Event, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Apply one event to the projection.

Provided Methods§

Source

fn tag(&self) -> Option<String>

Legacy tag filter. Default None. Implemented in terms of Self::filter so existing v1 readers keep working unchanged. Prefer Self::filter in new code.

Source

fn filter(&self) -> ReaderFilter

What stream of events this reader follows. Default returns ReaderFilter::Tag when Self::tag is Some, else ReaderFilter::All.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§