1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Projector base trait for CQRS read models.
//!
//! Phase 0 generic base for the `projection.rs` generator (Category C).
//!
//! Each generated `{Name}Projector` struct applies domain events to its
//! projection (read model). The structural contract — applying an event and
//! rebuilding from scratch — is identical for all entities. This trait
//! captures that contract so generated projectors can implement rather than
//! independently describe it.
//!
//! ## Generated output (after Phase 1):
//! ```rust,ignore
//! use backbone_core::projection::Projector;
//!
//! #[async_trait]
//! impl<R: OrderProjectionRepository> Projector<Order, OrderEvent> for OrderProjector<R> {
//! async fn project(&self, event: OrderEvent, sequence: i64) -> anyhow::Result<()> {
//! // dispatch to on_created / on_updated / on_deleted
//! }
//! async fn rebuild(&self) -> anyhow::Result<u64> {
//! self.repository.rebuild_all().await
//! }
//! }
//! ```
use async_trait;
/// Applies domain events to a CQRS read model (projection).
///
/// Type parameters:
/// - `E` — entity type the projection is built from
/// - `Evt` — domain event type (e.g. `OrderEvent` / `CrudEvent<Order>`)
///
/// The entity-specific fields of the projection struct, the event handler
/// methods, and the repository trait remain in the generated module.