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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
use PhantomData;
/// **English:**<br>
/// Event name and schema version supplied by the application.
/// Fields are public and unvalidated: an empty name or version zero is accepted. Equality compares
/// both fields. This value supplies no registry, serialization format, or migration dispatch.
///
/// **日本語:**<br>
/// アプリケーションが指定するイベント名とスキーマバージョンです。
/// フィールドは公開され検証されません。空の名前やバージョンゼロも許容します。等値比較は
/// 両フィールドを比較します。レジストリー、直列化形式、移行の振り分けは提供しません。
/// **English:**<br>
/// Type-level event identity independent of any particular event instance.
/// No [`crate::DomainEvent`] bound is required, and the trait does not validate the returned identity.
///
/// **日本語:**<br>
/// 個々のイベントインスタンスとは独立した、型単位のイベント識別情報です。
/// [`crate::DomainEvent`] の境界は要求せず、返された識別情報も検証しません。
/// **English:**<br>
/// Fallible owned transformation from an event representation back to the same Rust type.
/// Versions can be represented inside that type, but checking or advancing them is the
/// implementation's responsibility. No [`VersionedEvent`] bound or automatic version selection is used.
///
/// **日本語:**<br>
/// イベント表現を所有して受け取り、同じ Rust 型へ変換する、失敗し得る操作です。
/// 型の内部にバージョンを表現できますが、その検査や更新は実装が担います。
/// [`VersionedEvent`] の境界や自動的なバージョン選択は用いません。
/// **English:**<br>
/// Insertion-ordered sequence of upcasters of a single concrete type.
/// Each stage consumes the preceding output. The chain does not select stages by event identity,
/// sort versions, or restore an event after failure. Use an enum or another common upcaster type
/// when stages need different behaviors. It stores no event value and adds no locking.
///
/// Add stages explicitly; each successful result becomes the next input.
///
/// **日本語:**<br>
/// 同じ具体型の変換器を追加順に保持する列です。
/// 各段階は直前の出力を消費します。イベント識別情報による段階の選択、バージョンの並べ替え、
/// 失敗後のイベント復元はしません。異なる動作の段階には列挙型などの共通の変換器型を用います。
/// イベント値は保持せず、ロックも追加しません。
///
/// 段階を明示的に追加すると、各段階の成功結果が次の入力になります。
///
/// # Example / 使用例
///
/// ```rust
/// use ddd_toolkit_core::{EventUpcaster, UpcasterChain};
///
/// struct Append(&'static str);
/// impl EventUpcaster<String> for Append {
/// type Error = std::convert::Infallible;
/// fn upcast(&self, mut event: String) -> Result<String, Self::Error> {
/// event.push_str(self.0);
/// Ok(event)
/// }
/// }
/// let mut chain = UpcasterChain::new();
/// chain.push(Append("-v2"));
/// chain.push(Append("-v3"));
/// assert_eq!(chain.apply(String::from("v1")).unwrap(), "v1-v2-v3");
/// assert_eq!(chain.len(), 2);
/// ```