Skip to main content

ddd_toolkit_core/
domain_service.rs

1/// **English:**<br>
2/// Domain operation with owned input and implementation-selected output and error types.
3/// It supplies no transaction or retry logic. The shared receiver permits interior state;
4/// neither purity nor concurrent use is required by the trait.
5///
6/// **日本語:**<br>
7/// 所有する入力と、実装が選ぶ出力型・エラー型を持つドメイン操作です。
8/// トランザクションや再試行処理は提供しません。共有参照でも内部状態を持てるため、
9/// このトレイトは純粋性や並行利用を要求しません。
10pub trait DomainService<Input> {
11    /// **English:**<br>
12    /// Result value produced when the domain operation succeeds.
13    ///
14    /// **日本語:**<br>
15    /// ドメイン操作が成功した際の結果値です。
16    type Output;
17
18    /// **English:**<br>
19    /// Failure reported by the service, with no required error trait bounds.
20    ///
21    /// **日本語:**<br>
22    /// サービスが報告する失敗です。エラートレイトの境界は課しません。
23    type Error;
24
25    /// **English:**<br>
26    /// Consumes `input` to perform the operation, returning its output or error.
27    /// Implementations define side effects on success and failure and document any panic conditions.
28    ///
29    /// **日本語:**<br>
30    /// `input` を消費して操作を実行し、出力またはエラーを返します。
31    /// 成功・失敗時の副作用とパニックの条件は各実装が定め、文書化します。
32    fn execute(&self, input: Input) -> Result<Self::Output, Self::Error>;
33}
34
35/// **English:**<br>
36/// Fallible domain rule checked against a borrowed, possibly unsized context.
37/// Rejection and inability to evaluate are both represented by the implementation's error type.
38/// This trait does not enforce the rule automatically at other domain boundaries.
39///
40/// **日本語:**<br>
41/// サイズ不定でもよいコンテキストを借用して確認する、失敗し得るドメイン規則です。
42/// 拒否と評価不能は、どちらも実装のエラー型で表現します。
43/// 他のドメイン境界で規則を自動的に強制するものではありません。
44pub trait Policy<Context: ?Sized> {
45    /// **English:**<br>
46    /// Policy-specific rejection or evaluation failure.
47    ///
48    /// **日本語:**<br>
49    /// ポリシー固有の拒否または評価の失敗です。
50    type Error;
51
52    /// **English:**<br>
53    /// Returns `Ok(())` when `context` passes the rule, otherwise a policy error.
54    /// No ownership of the context is transferred; effects and panics depend on the implementation.
55    ///
56    /// **日本語:**<br>
57    /// `context` が規則を満たす場合は `Ok(())`、それ以外はポリシーエラーを返します。
58    /// コンテキストの所有権は移らず、副作用とパニックは実装に依存します。
59    fn check(&self, context: &Context) -> Result<(), Self::Error>;
60}