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§
Required Methods§
Sourcefn read_events<E>(
&self,
filter: EventFilter,
page: EventPage,
) -> impl Future<Output = Result<Vec<(E, StreamPosition)>, Self::Error>> + Sendwhere
E: Event,
fn read_events<E>(
&self,
filter: EventFilter,
page: EventPage,
) -> impl Future<Output = Result<Vec<(E, StreamPosition)>, Self::Error>> + Sendwhere
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 positionsErr(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 &Twhere
T: EventReader + Sync,
Blanket implementation allowing EventReader trait to work with references.
impl<T> EventReader for &Twhere
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.