Skip to main content

Entity

Derive Macro Entity 

Source
#[derive(Entity)]
{
    // Attributes available to this derive:
    #[entity]
}
Expand description

English:
Implements ddd_toolkit_core::Entity, a borrowed inherent id() accessor, and PartialEq, Eq, and Hash using only the identifier field.

Requires a named-field struct with exactly one #[entity(id)] field. Other fields do not participate in comparison or hashing; identifier types must implement the corresponding traits. No constructor or identifier validation is generated. Non-struct inputs, misplaced flags, missing or multiple identifier fields, unknown options, and missing core dependencies cause compile errors.

#[entity(trait_only)] generates only the domain trait implementation. It still requires #[entity(id)], but adds no inherent id(), standard traits, or extra bounds, so handwritten accessors and equality semantics are preserved.

日本語:
ddd_toolkit_core::Entity と識別子を借用する固有の id()、 識別子フィールドだけを使う PartialEq、Eq、Hash を実装します。

名前付き構造体に #[entity(id)] フィールドがちょうど一つ必要です。 他のフィールドは比較やハッシュに使いません。識別子型は対応するトレイトを 実装する必要があります。コンストラクターや識別子の検証は生成しません。 構造体以外、フラグの誤配置、識別子の欠落・複数指定、未知のオプション、 コア依存の欠落はコンパイルエラーになります。

#[entity(trait_only)] はドメイントレイト実装だけを生成します。 #[entity(id)] は引き続き必要ですが、固有の id()、標準トレイト、追加の 境界は生成しないため、手書きのアクセサーと等価性の意味を維持できます。

§Example / 使用例

use ddd_toolkit_macro::Entity;

#[derive(Entity)]
struct Order {
    #[entity(id)]
    id: u64,
    total: u32,
}
let first = Order { id: 1, total: 10 };
let updated = Order { id: 1, total: 20 };
assert!(first == updated);
assert_eq!(updated.id(), &1);