Expand description
Composable, strongly typed business rules.
A Specification evaluates a borrowed candidate. Specifications compose
through Specification::and, Specification::or, and
Specification::not without dynamic dispatch or heap allocation.
use specification_core::Specification;
let is_adult = |age: &u8| *age >= 18;
let is_senior = |age: &u8| *age >= 65;
let eligible = is_adult.and(is_senior.not());
assert!(eligible.is_satisfied_by(&42));
assert!(!eligible.is_satisfied_by(&70));Structs§
- AllOf
- A borrowed collection evaluated with logical AND.
- Always
- A specification that always returns
true. - And
- A specification that requires both of two specifications to be satisfied.
- AnyOf
- A borrowed collection evaluated with logical OR.
- Async
And - An asynchronous specification that requires both operands to succeed.
- Async
Not - An asynchronous specification that negates another specification.
- AsyncOr
- An asynchronous specification that accepts either operand.
- Boxed
Async Specification - An explicitly type-erased asynchronous specification.
- Boxed
Specification - An explicitly type-erased, owned specification.
- Cooldown
- A specification satisfied after a named timestamp is at least one duration old.
- Evaluation
Context - Immutable input data for specifications that need counters, flags, time, and application-specific user data.
- First
Match - Ordered, typed decisions selected by the first matching specification.
- Fixed
Clock - A clock fixed at one instant, useful for deterministic evaluation and tests.
- Flag
- A specification satisfied when a named context flag is true.
- MaxCount
- A specification satisfied while a named counter remains strictly below a maximum.
- Never
- A specification that always returns
false. - Not
- A specification that negates another specification’s result.
- Or
- A specification that requires either of two specifications to be satisfied.
- Shared
Specification - An explicitly type-erased specification that can be shared across threads.
Traits§
- Async
Specification - A runtime-neutral asynchronous rule over a borrowed,
Synccandidate. - Clock
- A deterministic source of evaluation time supplied by the caller.
- Decision
Specification - A rule that selects a typed decision for a candidate.
- Specification
- A deterministic boolean rule over a borrowed candidate.
Type Aliases§
- BoxFuture
- A boxed
Sendfuture used by the object-safe asynchronous adapter.