EventReader

Trait EventReader 

Source
pub trait EventReader {
    type Error;

    // Required method
    fn read_events<E>(
        &self,
        filter: EventFilter,
        page: EventPage,
    ) -> impl Future<Output = Result<Vec<(E, StreamPosition)>, Self::Error>> + Send
       where E: Event;
}
Expand description

Trait for reading events globally for projections.

EventReader provides access to all events in global order, which is required for building read models that aggregate data across streams.

§Pagination and Filtering

The read_events method requires explicit pagination via EventPage to prevent accidental memory exhaustion. Filtering is specified via EventFilter.

§Type Safety

The method is generic over the event type, allowing the caller to specify which event type to deserialize. Events that cannot be deserialized to the requested type are skipped.

Required Associated Types§

Source

type Error

Error type returned by read operations.

Required Methods§

Source

fn read_events<E>( &self, filter: EventFilter, page: EventPage, ) -> impl Future<Output = Result<Vec<(E, StreamPosition)>, Self::Error>> + Send
where E: Event,

Read events matching filter criteria with pagination.

Returns a vector of tuples containing the event and its global position. Events are ordered by their append time (oldest first).

§Type Parameters
  • E: The event type to deserialize events as
§Parameters
  • filter: Filtering criteria (stream prefix, etc.)
  • page: Pagination parameters (cursor position and limit)
§Returns
  • Ok(Vec<(E, StreamPosition)>): Events with their positions
  • Err(Self::Error): If the read operation fails
§Examples
let page = EventPage::first(BatchSize::new(100));
let events = reader.read_events(EventFilter::all(), page).await?;

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.

Implementations on Foreign Types§

Source§

impl<T> EventReader for &T
where T: EventReader + Sync,

Blanket implementation allowing EventReader trait to work with references.

This is a trivial forwarding implementation that cannot be meaningfully tested in isolation - mutations here would break all EventReader usage through references.

Source§

type Error = <T as EventReader>::Error

Source§

async fn read_events<E>( &self, filter: EventFilter, page: EventPage, ) -> Result<Vec<(E, StreamPosition)>, <&T as EventReader>::Error>
where E: Event,

Implementors§