Skip to main content

Specification

Trait Specification 

Source
pub trait Specification<T: ?Sized>: Sized {
    type Error;

    // Required method
    fn is_satisfied_by(&self, candidate: &T) -> Result<bool, Self::Error>;

    // Provided methods
    fn and<S>(self, other: S) -> And<Self, S>
       where S: Specification<T, Error = Self::Error> { ... }
    fn or<S>(self, other: S) -> Or<Self, S>
       where S: Specification<T, Error = Self::Error> { ... }
    fn not(self) -> Not<Self> { ... }
}
Expand description

English:
Fallible predicate over a borrowed candidate, with consuming boolean combinators. T may be unsized, but specification values must be sized. Combinations evaluate left to right, short-circuit on a decisive boolean, and propagate the first error without evaluating later rules. Implementations may use interior state; purity and thread safety are not required.

Combine rules over an unsized string candidate and invert the result.

日本語:
借用した候補に対する失敗し得る述語と、自身を消費する論理結合操作です。 T はサイズ不定でもよいですが、仕様の値自体はサイズ確定が必要です。結合は左から評価し、 真偽が確定すると短絡し、エラーでは後続の規則を評価せず最初のエラーを伝播します。 実装は内部状態を利用でき、純粋性やスレッド安全性は要求しません。

サイズ不定の文字列候補に対する規則を結合し、結果を反転します。

§Example / 使用例

use ddd_toolkit_core::Specification;

struct NonEmpty;
impl Specification<str> for NonEmpty {
    type Error = std::convert::Infallible;
    fn is_satisfied_by(&self, candidate: &str) -> Result<bool, Self::Error> {
        Ok(!candidate.is_empty())
    }
}
let rule = NonEmpty.and(NonEmpty).not();
assert_eq!(rule.is_satisfied_by("order"), Ok(false));
assert_eq!(rule.is_satisfied_by(""), Ok(true));

Required Associated Types§

Source

type Error

English:
Evaluation failure, distinct from a successfully evaluated false result.

日本語:
正常に評価された false とは区別される、評価の失敗です。

Required Methods§

Source

fn is_satisfied_by(&self, candidate: &T) -> Result<bool, Self::Error>

English:
Returns whether candidate satisfies the rule or why evaluation failed. The candidate remains borrowed; side effects and panic conditions depend on the rule.

日本語:
candidate が規則を満たすか、評価が失敗した理由を返します。 候補は借用のままで、副作用とパニックの条件は規則に依存します。

Provided Methods§

Source

fn and<S>(self, other: S) -> And<Self, S>
where S: Specification<T, Error = Self::Error>,

English:
Consumes both rules to form And, evaluating other only if this rule returns Ok(true). Both must share an error type. Construction evaluates neither rule.

日本語:
両規則を消費して And を作り、この規則が Ok(true) の場合のみ other を評価します。 エラー型は共通でなければなりません。構築時にはどちらも評価しません。

Source

fn or<S>(self, other: S) -> Or<Self, S>
where S: Specification<T, Error = Self::Error>,

English:
Consumes both rules to form Or, evaluating other only if this rule returns Ok(false). An error from this rule is returned without consulting other.

日本語:
両規則を消費して Or を作り、この規則が Ok(false) の場合のみ other を評価します。 この規則のエラーは other を評価せずに返します。

Source

fn not(self) -> Not<Self>

English:
Consumes this rule to form Not, which flips successful booleans and preserves errors.

日本語:
この規則を消費して Not を作り、成功時の真偽を反転し、エラーは保持します。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: ?Sized, L, R> Specification<T> for And<L, R>
where L: Specification<T>, R: Specification<T, Error = L::Error>,

Source§

impl<T: ?Sized, L, R> Specification<T> for Or<L, R>
where L: Specification<T>, R: Specification<T, Error = L::Error>,

Source§

impl<T: ?Sized, S> Specification<T> for Not<S>
where S: Specification<T>,