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