Skip to main content

Crate ddd_toolkit_macro

Crate ddd_toolkit_macro 

Source
Expand description

English:
Derive value objects, identity-based entities, domain-event markers, and aggregate event queues for ddd-toolkit-core.

Add both ddd-toolkit-macro and ddd-toolkit-core to your dependencies. Expansion resolves the core package by name, including renamed dependencies; a facade dependency alone is not resolved. These macros generate implementations at compile time, not runtime synchronization or persistence.

Use ValueObject for field-based equality, Entity for identity-based equality, DomainEvent for event types, and AggregateRoot for a draining event queue. Do not separately derive traits that a macro already implements.

日本語:
ddd-toolkit-core 向けに、値オブジェクト、識別子で比較する エンティティ、ドメインイベントのマーカー、集約のイベントキューを導出します。

依存関係には ddd-toolkit-macro と ddd-toolkit-core の両方が必要です。 コアのパッケージ名から参照先を解決するため依存の別名に対応しますが、 ファサードだけの依存は解決しません。実装をコンパイル時に生成するもので、 実行時の同期や永続化は行いません。

フィールドの値で比較する型には ValueObject、識別子で比較する型には Entity、イベント型には DomainEvent、イベントを取り出して空にする キューには AggregateRoot を使います。生成済みのトレイトを重複して導出しないでください。

§Example / 使用例

use ddd_toolkit_macro::ValueObject;

#[derive(ValueObject)]
struct Quantity(u32);

let quantity = Quantity::new(3);
assert_eq!(quantity.as_inner(), &3);
assert_eq!(quantity.into_inner(), 3);

Derive Macros§

AggregateRoot
English:
Implements ddd_toolkit_core::AggregateRoot using a struct’s #[aggregate(events)] vector as its pending event queue.
DomainEvent
English:
Implements the empty ddd_toolkit_core::DomainEvent marker for a struct or enum, preserving its generic parameters and where clause.
Entity
English:
Implements ddd_toolkit_core::Entity, a borrowed inherent id() accessor, and PartialEq, Eq, and Hash using only the identifier field.
ValueObject
English:
Implements ddd_toolkit_core::ValueObject and value-based Debug, Clone, PartialEq, Eq, and Hash, with corresponding field bounds.