Skip to main content

Specification

Trait Specification 

Source
pub trait Specification<T: ?Sized> {
    // Required method
    fn is_satisfied_by(&self, candidate: &T) -> bool;

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

A deterministic boolean rule over a borrowed candidate.

Implement this trait for a focused business rule, then compose it with the provided boolean combinators. Evaluation borrows the candidate, so rules do not take ownership of the value they inspect.

Required Methods§

Source

fn is_satisfied_by(&self, candidate: &T) -> bool

Returns whether candidate satisfies this rule.

Provided Methods§

Source

fn and<Other>(self, other: Other) -> And<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical AND.

The resulting And evaluates this rule first. It evaluates other only when this rule returns true.

Source

fn or<Other>(self, other: Other) -> Or<Self, Other>
where Self: Sized, Other: Specification<T>,

Combines this rule with other using short-circuiting logical OR.

The resulting Or evaluates this rule first. It evaluates other only when this rule returns false.

Source

fn not(self) -> Not<Self>
where Self: Sized,

Creates a rule that negates this rule’s result.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

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

Source§

impl<T: ?Sized, Left, Right> Specification<T> for And<Left, Right>
where Left: Specification<T>, Right: Specification<T>,

Source§

impl<T: ?Sized, Left, Right> Specification<T> for Or<Left, Right>
where Left: Specification<T>, Right: Specification<T>,

Source§

impl<T: ?Sized, Predicate> Specification<T> for Predicate
where Predicate: Fn(&T) -> bool,

Source§

impl<T: ?Sized, SpecificationType> Specification<T> for AllOf<'_, SpecificationType>
where SpecificationType: Specification<T>,

Source§

impl<T: ?Sized, SpecificationType> Specification<T> for AnyOf<'_, SpecificationType>
where SpecificationType: Specification<T>,

Source§

impl<T: ?Sized> Specification<T> for Always

Source§

impl<T: ?Sized> Specification<T> for BoxedSpecification<T>

Source§

impl<T: ?Sized> Specification<T> for Never

Source§

impl<T: ?Sized> Specification<T> for SharedSpecification<T>

Source§

impl<UserData, ClockType> Specification<EvaluationContext<UserData>> for Cooldown<ClockType>
where ClockType: Clock,

Source§

impl<UserData> Specification<EvaluationContext<UserData>> for Flag

Source§

impl<UserData> Specification<EvaluationContext<UserData>> for MaxCount