ddd_toolkit_core/value_object.rs
1/// **English:** Represents a domain value by wrapping an inner value.
2///
3/// Implementors provide both a borrowed view through [`ValueObject::as_inner`] and an ownership-
4/// consuming conversion through [`ValueObject::into_inner`]. Equality, hashing, validation, and
5/// serialization policies remain specific to the implementing type.
6///
7/// **日本語:** 内包値をラップしてドメイン上の値を表現します。
8///
9/// 実装型は [`ValueObject::as_inner`] による借用ビューと、[`ValueObject::into_inner`] による
10/// 所有権を消費する変換を提供します。等価性、ハッシュ、検証、シリアライズの方針は実装型ごとに定義します。
11pub trait ValueObject {
12 /// **English:** The value type wrapped by this value object.
13 ///
14 /// **日本語:** この値オブジェクトが内包する値の型です。
15 type Inner;
16
17 /// **English:** Borrows the wrapped value without consuming the value object.
18 ///
19 /// The returned reference is tied to `self` and reflects the implementation's current inner
20 /// value. This method does not mutate the value object and does not panic by itself.
21 ///
22 /// **日本語:** 値オブジェクトを消費せずに内包値を借用します。
23 ///
24 /// 返される参照の有効期間は `self` の借用に結び付き、実装型が現在保持する内包値を反映します。
25 /// このメソッド自体は値オブジェクトを変更せず、通常はパニックしません。
26 fn as_inner(&self) -> &Self::Inner;
27
28 /// **English:** Consumes the value object and returns its wrapped value.
29 ///
30 /// After this call, the value object cannot be used again. Implementations may perform
31 /// validation or other work before returning, so callers should follow the implementation's
32 /// documented behavior.
33 ///
34 /// **日本語:** 値オブジェクトを消費して内包値を返します。
35 ///
36 /// 呼び出し後は値オブジェクトを再利用できません。実装は返却前に検証などの処理を行う場合があるため、
37 /// 呼び出し側は実装型が定める動作に従ってください。
38 fn into_inner(self) -> Self::Inner;
39}