ddd_toolkit_core/event_consumption.rs
1use crate::DomainEvent;
2
3/// **English:** Handles a borrowed domain event synchronously.
4///
5/// Implementations define side effects, error and panic conditions, and duplicate handling.
6/// This port supplies no acknowledgement, retry, ordering, or deduplication mechanism.
7///
8/// **日本語:** 借用したドメインイベントを同期的に処理します。
9///
10/// 副作用、エラーとパニックの条件、重複の扱いは実装が定めます。
11/// このポートは確認応答、再試行、順序制御、重複排除の機構を提供しません。
12pub trait EventConsumer {
13 /// **English:** Domain event accepted by this consumer.
14 ///
15 /// **日本語:** このコンシューマーが受け付けるドメインイベントです。
16 type Event: DomainEvent;
17 /// **English:** Failure reported by the consuming implementation.
18 ///
19 /// **日本語:** 処理の実装が報告する失敗です。
20 type Error;
21
22 /// **English:** Processes `event`, returning `Ok(())` on completion or the handler's error.
23 /// An error does not imply that earlier side effects were rolled back.
24 ///
25 /// **日本語:** `event` を処理し、完了時に `Ok(())`、失敗時にハンドラーのエラーを返します。
26 /// エラーは、それ以前の副作用のロールバックを意味しません。
27 fn consume(&mut self, event: &Self::Event) -> Result<(), Self::Error>;
28}
29
30/// **English:** Applies domain events to a read model synchronously.
31///
32/// Storage, event ordering, idempotency, and panic conditions belong to the implementation;
33/// this trait does not replay or persist events itself.
34///
35/// **日本語:** ドメインイベントを読み取りモデルへ同期的に適用します。
36///
37/// 保存方法、イベント順序、冪等性、パニック条件は実装が定めます。
38/// このトレイト自体はイベントの再生や永続化を行いません。
39pub trait Projection {
40 /// **English:** Event type used to update the read model.
41 ///
42 /// **日本語:** 読み取りモデルの更新に使うイベント型です。
43 type Event: DomainEvent;
44 /// **English:** Failure produced while updating the projection.
45 ///
46 /// **日本語:** プロジェクションの更新中に生じる失敗です。
47 type Error;
48
49 /// **English:** Updates the projection from `event` or returns an implementation error.
50 /// Rollback of partial updates is not specified by this signature.
51 ///
52 /// **日本語:** `event` からプロジェクションを更新するか、実装のエラーを返します。
53 /// 部分的な更新のロールバックは、このシグネチャでは規定しません。
54 fn project(&mut self, event: &Self::Event) -> Result<(), Self::Error>;
55}