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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#![allow(clippy::type_complexity)]
use crate::{AggregateRoot, AppendError, AppendResult, Entity, ExpectedRevision, LoadResult};
use std::future::Future;
use std::pin::Pin;
/// **English:**<br>
/// Asynchronous event-stream storage using the result types of [`crate::EventStore`].
///
/// Returned futures are `Send` and borrow the store and identifier for `'a`; no executor or
/// synchronization is provided. Adapters define atomicity, durability, writer coordination,
/// panic conditions, and the outcome of cancelling an operation by dropping its future.
/// Cancellation does not by itself imply that writes were rolled back.
///
/// **日本語:**<br>
/// [`crate::EventStore`] と同じ結果型を使う非同期イベントストリームストアです。
///
/// 返される Future は `Send` で、ストアと識別子を `'a` の間借用します。
/// 実行器や同期機構は提供しません。原子性、永続性、書き込みの調整、パニック条件、
/// Future の破棄によるキャンセルの結果はアダプターが定めます。
/// キャンセル自体は書き込みのロールバックを意味しません。
pub trait AsyncEventStore
where
<Self::Aggregate as AggregateRoot>::Event: Send,
<Self::Aggregate as Entity>::Id: Sync,
{
/// **English:**<br>
/// Aggregate supplying the stream identifier and transferable event type.
/// Its identifier must be `Sync`, and its events must be `Send`.
///
/// **日本語:**<br>
/// ストリーム識別子と受け渡し可能なイベント型を定める集約です。
/// 識別子には `Sync`、イベントには `Send` が必要です。
type Aggregate: AggregateRoot + Send;
/// **English:**<br>
/// Storage error transferable with the future's result.
///
/// **日本語:**<br>
/// Future の結果とともに受け渡せるストレージエラーです。
type Error: Send;
/// **English:**<br>
/// Loads the complete history for `id` or returns [`LoadResult::NoStream`].
/// Storage failures use `Self::Error`, not the absent-stream result.
///
/// **日本語:**<br>
/// `id` の完全な履歴、または [`LoadResult::NoStream`] を返します。
/// ストレージ障害はストリーム不在ではなく `Self::Error` で報告します。
fn load<'a>(
&'a self,
id: &'a <Self::Aggregate as Entity>::Id,
) -> Pin<
Box<
dyn Future<
Output = Result<
LoadResult<<Self::Aggregate as AggregateRoot>::Event>,
Self::Error,
>,
> + Send
+ 'a,
>,
>;
/// **English:**<br>
/// Takes ownership of `events` to append in vector order under `expected`.
/// The future returns the final revision or an [`AppendError`] for an empty batch,
/// revision conflict, revision exhaustion, or adapter failure. The batch is not returned
/// on error; partial-write and retry behavior must be documented by the adapter.
///
/// **日本語:**<br>
/// `events` の所有権を受け取り、`expected` を条件にベクター順で追加します。
/// Future は最終リビジョン、または空バッチ、リビジョン競合、リビジョン枯渇、
/// アダプター障害を示す [`AppendError`] を返します。エラー時にバッチは返されません。
/// 部分書き込みと再試行の挙動はアダプターが文書化する必要があります。
fn append<'a>(
&'a mut self,
id: &'a <Self::Aggregate as Entity>::Id,
expected: ExpectedRevision,
events: Vec<<Self::Aggregate as AggregateRoot>::Event>,
) -> Pin<Box<dyn Future<Output = Result<AppendResult, AppendError<Self::Error>>> + Send + 'a>>;
}