Skip to main content

ddd_toolkit_core/
domain_service.rs

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