ProjectionBuilder

Struct ProjectionBuilder 

Source
pub struct ProjectionBuilder<'a, S, P>
where S: EventStore, P: Projection<Id = S::Id>,
{ /* private fields */ }
Expand description

Builder used to configure which events should be loaded for a projection.

Implementations§

Source§

impl<'a, S, P> ProjectionBuilder<'a, S, P>
where S: EventStore, P: Projection<Id = S::Id>,

Source

pub fn event<E>(self) -> Self

Register a specific event type to load from all aggregates.

§Type Constraints

The store’s metadata type must be convertible to the projection’s metadata type. Clone is required because event handlers receive metadata by reference, but Into::into() requires ownership. The metadata is cloned once per event.

§Example
builder.event::<ProductRestocked>()  // All products
Source

pub fn events<E>(self) -> Self

Register all event kinds supported by a ProjectionEvent sum type across all aggregates.

This is primarily intended for subscribing to an aggregate’s generated event enum (A::Event from #[derive(Aggregate)]) as a single “unit”, rather than registering each DomainEvent type individually.

§Example
builder.events::<AccountEvent>() // All accounts, all account event variants
Source

pub fn event_for<A, E>(self, aggregate_id: &S::Id) -> Self
where A: Aggregate<Id = S::Id>, E: DomainEvent, P: ApplyProjection<E>, S::Metadata: Clone + Into<P::Metadata>,

Register a specific event type to load from a specific aggregate instance.

Use this when you only care about a single event kind. If you want to subscribe to an aggregate’s full event enum (A::Event), prefer ProjectionBuilder::events_for.

§Example
builder.event_for::<Account, FundsDeposited>(&account_id); // One account stream
Source

pub fn events_for<A>(self, aggregate_id: &S::Id) -> Self
where A: Aggregate<Id = S::Id>, A::Event: ProjectionEvent, P: ApplyProjection<A::Event>, S::Metadata: Clone + Into<P::Metadata>,

Register all event kinds for a specific aggregate instance.

This subscribes the projection to the aggregate’s event sum type (A::Event) and loads all events in that stream that correspond to A::Event::EVENT_KINDS.

§Example
let history = repository
    .build_projection::<AccountHistory>()
    .events_for::<Account>(&account_id)
    .load()?;
Source

pub async fn load( self, ) -> Result<P, ProjectionError<S::Error, <S::Codec as Codec>::Error>>

Replays the configured events and materializes the projection.

Events are dispatched to the projection via the registered handlers, which deserialize and apply each event through the appropriate ApplyProjection implementation.

§Errors

Returns ProjectionError when the store fails to load events or when an event cannot be deserialized.

Auto Trait Implementations§

§

impl<'a, S, P> Freeze for ProjectionBuilder<'a, S, P>

§

impl<'a, S, P> !RefUnwindSafe for ProjectionBuilder<'a, S, P>

§

impl<'a, S, P> Send for ProjectionBuilder<'a, S, P>

§

impl<'a, S, P> Sync for ProjectionBuilder<'a, S, P>

§

impl<'a, S, P> Unpin for ProjectionBuilder<'a, S, P>
where <S as EventStore>::Id: Unpin, <S as EventStore>::Position: Unpin,

§

impl<'a, S, P> !UnwindSafe for ProjectionBuilder<'a, S, P>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more