pub struct ProjectionEngine { /* private fields */ }Expand description
Engine for managing multiple projections.
The ProjectionEngine:
- Registers fully composed
Projectioninstances - 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
impl ProjectionEngine
Sourcepub fn new(event_store: Box<dyn EventStore>) -> Self
pub fn new(event_store: Box<dyn EventStore>) -> Self
Create a new projection engine.
Sourcepub fn register(&mut self, projection: Box<dyn Projection>)
pub fn register(&mut self, projection: Box<dyn Projection>)
Register a fully composed projection.
Sourcepub fn register_projector(
&mut self,
projector: Box<dyn Projector>,
store: Arc<dyn ReadModelStore>,
table: impl Into<String>,
)
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.
Sourcepub async fn process(&self, event: &Event) -> ProjectionResult<()>
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.
Sourcepub async fn process_batch(&self, events: Vec<Event>) -> ProjectionResult<()>
pub async fn process_batch(&self, events: Vec<Event>) -> ProjectionResult<()>
Process multiple events in sequence.
Sourcepub async fn rebuild_all(&self) -> ProjectionResult<()>
pub async fn rebuild_all(&self) -> ProjectionResult<()>
Rebuild all registered projections from the event store.
Sourcepub async fn rebuild_projection(&self, name: &str) -> ProjectionResult<()>
pub async fn rebuild_projection(&self, name: &str) -> ProjectionResult<()>
Rebuild a specific projection by name.
Sourcepub fn projection_count(&self) -> usize
pub fn projection_count(&self) -> usize
Get number of registered projections.
Sourcepub fn projection_names(&self) -> Vec<String>
pub fn projection_names(&self) -> Vec<String>
Get names of all registered projections.
Sourcepub fn all_handled_event_types(&self) -> Vec<String>
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§
impl !RefUnwindSafe for ProjectionEngine
impl !UnwindSafe for ProjectionEngine
impl Freeze for ProjectionEngine
impl Send for ProjectionEngine
impl Sync for ProjectionEngine
impl Unpin for ProjectionEngine
impl UnsafeUnpin for ProjectionEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more