Skip to main content

Module specification

Module specification 

Source
Expand description

Specification Pattern - Business Rules as Objects

The Specification pattern encapsulates business rules that can be combined and reused. This is a core DDD tactical pattern.

§Example

ⓘ
use backbone_core::specification::{Specification, AndSpecification};

// Define a specification
struct UserIsActive;

impl Specification<User> for UserIsActive {
    type Error = String;

    fn is_satisfied_by(&self, user: &User) -> Result<bool, Self::Error> {
        Ok(user.status == UserStatus::Active)
    }
}

// Combine specifications
let spec = UserIsActive.and(UserHasVerifiedEmail);
let is_valid = spec.is_satisfied_by(&user)?;

Structs§

AlwaysFalse
Always returns false
AlwaysTrue
Always returns true
AndSpecification
AND specification - both left and right must be satisfied
NotSpecification
NOT specification - negates the inner specification
OrSpecification
OR specification - either left or right must be satisfied
PredicateSpecification
Specification using a closure
SpecificationEvaluator
Evaluates multiple specifications and collects results
SpecificationResult
Result of evaluating a specification with detailed information

Traits§

Specification
Core Specification trait

Functions§

predicate
Helper function to create a predicate specification