Expand description
Specification pattern — composable predicates over a domain type.
Useful for invariant checks, query filters, and command routing.
Specifications combine with and, or, and not so complex
predicates stay declarative.
ⓘ
struct OverThreshold(i64);
impl Specification<Order> for OverThreshold {
fn is_satisfied_by(&self, o: &Order) -> bool { o.amount > self.0 }
}
struct InRegion(String);
impl Specification<Order> for InRegion {
fn is_satisfied_by(&self, o: &Order) -> bool { o.region == self.0 }
}
let spec = OverThreshold(100).and(InRegion("EU".into()));
orders.iter().filter(|o| spec.is_satisfied_by(o));Structs§
- AndSpec
- FnSpec
- Convenience: lift any
Fn(&T) -> boolinto aSpecification. - NotSpec
- OrSpec
Traits§
- Specification
- Composable predicate over
T.