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§
Required Methods§
Sourcefn is_satisfied_by(&self, candidate: &T) -> Result<bool, Self::Error>
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§
Sourcefn and<S>(self, other: S) -> And<Self, S>where
S: Specification<T, Error = Self::Error>,
fn and<S>(self, other: S) -> And<Self, S>where
S: Specification<T, Error = Self::Error>,
Sourcefn or<S>(self, other: S) -> Or<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>,
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".