pub trait Specification<T>: Send + Sync {
type Error: Debug + Send;
// Required method
fn is_satisfied_by(&self, candidate: &T) -> Result<bool, Self::Error>;
// Provided methods
fn and<S>(self, other: S) -> AndSpecification<Self, S, T>
where Self: Sized,
S: Specification<T> { ... }
fn or<S>(self, other: S) -> OrSpecification<Self, S, T>
where Self: Sized,
S: Specification<T> { ... }
fn not(self) -> NotSpecification<Self, T>
where Self: Sized { ... }
}Expand description
Core Specification trait
Specifications encapsulate business rules that can be:
- Combined with AND, OR, NOT operators
- Reused across different parts of the application
- Tested in isolation
§Type Parameters
T: The type of entity being validated
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn and<S>(self, other: S) -> AndSpecification<Self, S, T>where
Self: Sized,
S: Specification<T>,
fn and<S>(self, other: S) -> AndSpecification<Self, S, T>where
Self: Sized,
S: Specification<T>,
Combine with another specification using AND
Sourcefn or<S>(self, other: S) -> OrSpecification<Self, S, T>where
Self: Sized,
S: Specification<T>,
fn or<S>(self, other: S) -> OrSpecification<Self, S, T>where
Self: Sized,
S: Specification<T>,
Combine with another specification using OR
Sourcefn not(self) -> NotSpecification<Self, T>where
Self: Sized,
fn not(self) -> NotSpecification<Self, T>where
Self: Sized,
Negate this specification
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".