Skip to main content

EventCollector

Struct EventCollector 

Source
pub struct EventCollector<E> { /* private fields */ }
Expand description

A projector that collects events for testing assertions.

EventCollector stores events in shared, thread-safe storage (Arc<Mutex<Vec<E>>>) so that events can be inspected after projection completes. This is the primary mechanism for black-box integration testing in EventCore.

§Type Parameters

  • E: The event type to collect. Must be Clone so that events() can return owned copies without consuming the collector.

§Thread Safety

The internal storage uses Arc<Mutex<_>> to allow the collector to be shared across threads (e.g., between the projection runner and test assertions).

Implementations§

Source§

impl<E> EventCollector<E>

Source

pub fn new(storage: Arc<Mutex<Vec<E>>>) -> Self

Creates a new EventCollector with the provided shared storage.

§Arguments
  • storage - An Arc<Mutex<Vec<E>>> that will hold collected events. The same storage can be cloned before passing to enable access to collected events after the collector is moved.
Source

pub fn events(&self) -> Vec<E>
where E: Clone,

Returns a clone of all collected events.

This method clones the internal vector, allowing inspection without consuming the collector. The Clone bound on E enables this behavior.

Trait Implementations§

Source§

impl<E: Debug> Debug for EventCollector<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Send + 'static> Projector for EventCollector<E>

Source§

type Event = E

The domain event type this projector handles.
Source§

type Error = Infallible

The error type returned when projection fails.
Source§

type Context = ()

Shared context for database connections, caches, etc.
Source§

fn apply( &mut self, event: Self::Event, _position: StreamPosition, _ctx: &mut Self::Context, ) -> Result<(), Self::Error>

Process a single event and update the read model. Read more
Source§

fn name(&self) -> &str

Return a unique identifier for this projector. Read more
Source§

fn on_error(&mut self, _ctx: FailureContext<'_, Self::Error>) -> FailureStrategy

Handle event processing errors and determine failure strategy. Read more

Auto Trait Implementations§

§

impl<E> Freeze for EventCollector<E>

§

impl<E> RefUnwindSafe for EventCollector<E>

§

impl<E> Send for EventCollector<E>
where E: Send,

§

impl<E> Sync for EventCollector<E>
where E: Send,

§

impl<E> Unpin for EventCollector<E>

§

impl<E> UnsafeUnpin for EventCollector<E>

§

impl<E> UnwindSafe for EventCollector<E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V