Skip to main content

ddd_toolkit_core/
entity.rs

1/// **English:** Identifies a domain object by an associated identifier type.
2///
3/// Implementors expose the identifier without transferring ownership. The trait does not require
4/// identifiers to be comparable, serializable, or globally unique; those constraints belong to the
5/// domain type or to the repository that uses it.
6///
7/// **日本語:** 関連付けられた識別子型によってドメインオブジェクトを識別します。
8///
9/// 実装型は所有権を移さずに識別子を公開します。識別子の比較可能性、シリアライズ可能性、
10/// グローバルな一意性は要求しないため、必要な制約はドメイン型または利用するリポジトリで定義します。
11pub trait Entity {
12    /// **English:** The type used to identify this entity.
13    ///
14    /// **日本語:** このエンティティの識別に使う型です。
15    type Id;
16
17    /// **English:** Borrows this entity's identifier.
18    ///
19    /// The returned reference is tied to `self`, so the identifier remains owned by the entity and
20    /// cannot outlive the borrow. This method does not mutate the entity and does not panic by itself.
21    ///
22    /// **日本語:** このエンティティの識別子を借用します。
23    ///
24    /// 返される参照の有効期間は `self` の借用に結び付くため、識別子の所有権はエンティティに残り、
25    /// 借用より長く存続することはありません。このメソッド自体はエンティティを変更せず、通常はパニックしません。
26    fn id(&self) -> &Self::Id;
27}