#[derive(AggregateRoot)]
{
// Attributes available to this derive:
#[aggregate]
}
Expand description
English:
Implements ddd_toolkit_core::AggregateRoot using a struct’s
#[aggregate(events)] vector as its pending event queue.
Requires a named-field struct that already implements ddd_toolkit_core::Entity
(for example via Entity) and exactly one marked field spelled Vec<Event>
or std::vec::Vec<Event>. Type aliases and other vector paths are not accepted;
Event must implement ddd_toolkit_core::DomainEvent (see DomainEvent).
record_event appends with Vec::push, preserving insertion order, and may
allocate. pull_events moves out the vector with core::mem::take, leaving an
empty queue; repeated pulls return empty vectors until another event is recorded.
These are trait methods, not inherent methods; import the core trait to call
them. Both require exclusive mutable access, with no locking, event publication,
persistence, or domain-state update generated. Vector growth has the usual
allocation and capacity limits of Vec::push.
Unsupported shapes, missing or duplicate queues, unknown or valued flags,
missing trait implementations, and missing core dependencies fail to compile.
日本語:
構造体の #[aggregate(events)] ベクターを未処理イベントキュー
として ddd_toolkit_core::AggregateRoot を実装します。
ddd_toolkit_core::Entity を実装済みの名前付き構造体(例: Entity による導出)
と、Vec<Event> または std::vec::Vec<Event> と記述されたキューフィールドが
ちょうど一つ必要です。型エイリアスや他のベクターパスは受け付けません。
Event は ddd_toolkit_core::DomainEvent を実装する必要があります(DomainEvent)。
record_event は Vec::push で挿入順に追加し、メモリを確保する場合があります。
pull_events は core::mem::take でベクターを取り出し、キューを空にします。
次の記録まで再度取り出しても空のベクターを返します。固有メソッドではなくトレイト
メソッドなので、呼び出すにはコアのトレイトをインポートしてください。
どちらも排他的な可変アクセスを要求し、ロック、イベント配信、永続化、ドメイン状態の
更新は生成しません。キューの拡張には Vec::push と同じメモリ確保・容量制限があります。
非対応の形状、キューの欠落・重複、未知または値付きフラグ、必要なトレイト実装や
コア依存の欠落はコンパイルエラーになります。
§Example / 使用例
use ddd_toolkit_core::AggregateRoot as _;
use ddd_toolkit_macro::{AggregateRoot, DomainEvent, Entity};
#[derive(DomainEvent)]
struct Placed;
#[derive(Entity, AggregateRoot)]
struct Order {
#[entity(id)]
id: u64,
#[aggregate(events)]
events: Vec<Placed>,
}
let mut order = Order { id: 1, events: Vec::new() };
order.record_event(Placed);
assert_eq!(order.pull_events().len(), 1);
assert!(order.pull_events().is_empty());