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