ddd_toolkit_core/unit_of_work.rs
1/// **English:**<br>
2/// Explicit registration, commit, and rollback operations for a set of changes.
3/// Implementations define transaction boundaries, atomicity, ordering, and whether repeated
4/// commits or rollback after commit are valid. This trait tracks no lifecycle state and provides
5/// no automatic rollback on drop or error. It imposes no `Send` or `Sync` bounds.
6///
7/// **日本語:**<br>
8/// 変更の登録、コミット、ロールバックを明示的に行う操作です。
9/// トランザクション境界、原子性、順序、コミットの繰り返しやコミット後のロールバックの可否は
10/// 実装が定めます。このトレイトはライフサイクル状態を追跡せず、破棄やエラー時の自動ロールバックも
11/// 提供しません。`Send` や `Sync` の境界は課しません。
12pub trait UnitOfWork {
13 /// **English:**<br>
14 /// Owned operation or data accepted for participation in this unit of work.
15 ///
16 /// **日本語:**<br>
17 /// この作業単位に参加させる、所有された操作またはデータです。
18 type Change;
19
20 /// **English:**<br>
21 /// Shared error type for registration, commit, and rollback failures.
22 ///
23 /// **日本語:**<br>
24 /// 登録、コミット、ロールバックの失敗に共通するエラー型です。
25 type Error;
26
27 /// **English:**<br>
28 /// Consumes `change` to register it, or reports a registration error.
29 /// Whether the change takes effect immediately or is buffered, and what remains on error,
30 /// are implementation-defined; ownership is not returned by this signature.
31 ///
32 /// **日本語:**<br>
33 /// `change` を消費して登録するか、登録エラーを返します。
34 /// 即時に反映するかバッファするかと、エラー時に残る状態は実装が定めます。
35 /// このシグネチャでは所有権を返しません。
36 fn enlist(&mut self, change: Self::Change) -> Result<(), Self::Error>;
37
38 /// **English:**<br>
39 /// Requests committing the registered work and returns success or a commit error.
40 /// The implementation defines durability and partial-failure recovery; an error alone does
41 /// not establish that no changes were persisted.
42 ///
43 /// **日本語:**<br>
44 /// 登録した作業のコミットを要求し、成功またはコミットエラーを返します。
45 /// 永続性と部分失敗からの回復は実装が定めます。エラーだけでは、変更が一切永続化されていないと
46 /// 判断できません。
47 fn commit(&mut self) -> Result<(), Self::Error>;
48
49 /// **English:**<br>
50 /// Requests discarding or undoing work, returning a rollback error if it fails.
51 /// The implementation specifies which changes can be undone and whether another attempt is valid.
52 ///
53 /// **日本語:**<br>
54 /// 作業の破棄や取り消しを要求し、失敗時にはロールバックエラーを返します。
55 /// 取り消せる変更の範囲と再試行の可否は実装が定めます。
56 fn rollback(&mut self) -> Result<(), Self::Error>;
57}