Skip to main content

ProjectionEngine

Struct ProjectionEngine 

Source
pub struct ProjectionEngine { /* private fields */ }
Expand description

Engine for managing multiple projections.

The ProjectionEngine:

  • Registers fully composed Projection instances
  • Routes events to interested projections
  • Rebuilds projections from the event store
  • Provides convenience registration via register_projector

§Example

let event_store = Box::new(sqlite_event_store);
let mut engine = ProjectionEngine::new(event_store);

// Option 1: register a pre-composed projection
engine.register(Box::new(projection_unit));

// Option 2: convenience — register projector + store directly
engine.register_projector(Box::new(UserListProjector), store.clone(), "users_view");

// Process events
engine.process(&event).await?;

// Rebuild all projections from event store
engine.rebuild_all().await?;

Implementations§

Source§

impl ProjectionEngine

Source

pub fn new(event_store: Box<dyn EventStore>) -> Self

Create a new projection engine.

Source

pub fn register(&mut self, projection: Box<dyn Projection>)

Register a fully composed projection.

Source

pub fn register_projector( &mut self, projector: Box<dyn Projector>, store: Arc<dyn ReadModelStore>, table: impl Into<String>, )

Convenience: register a projector + store as a ProjectionUnit.

Source

pub async fn process(&self, event: &Event) -> ProjectionResult<()>

Process a single event through all interested projections.

Routes the event to projections whose handles() includes the event type.

Source

pub async fn process_batch(&self, events: Vec<Event>) -> ProjectionResult<()>

Process multiple events in sequence.

Source

pub async fn rebuild_all(&self) -> ProjectionResult<()>

Rebuild all registered projections from the event store.

Source

pub async fn rebuild_projection(&self, name: &str) -> ProjectionResult<()>

Rebuild a specific projection by name.

Source

pub fn projection_count(&self) -> usize

Get number of registered projections.

Source

pub fn projection_names(&self) -> Vec<String>

Get names of all registered projections.

Source

pub fn all_handled_event_types(&self) -> Vec<String>

Union of every event type any registered projection handles. Used by ProjectionEngineHandler to declare its handles() set when subscribing to an EventBus.

Auto Trait Implementations§

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> 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
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> Same for T

Source§

type Output = T

Should always be Self
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<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