Skip to main content

ddd_toolkit_core/
value_object.rs

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