pub struct Policy<T> { /* private fields */ }Expand description
A cloneable, thread-safe acceptance rule for values of type T.
Implementations§
Source§impl<T: 'static> Policy<T>
impl<T: 'static> Policy<T>
Sourcepub fn allow_if(
name: impl Into<String>,
expectation: impl Into<String>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> Result<Self, Error>
pub fn allow_if( name: impl Into<String>, expectation: impl Into<String>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> Result<Self, Error>
Creates a leaf policy from a predicate and a fixed expectation message.
Sourcepub fn explain_with(
name: impl Into<String>,
evaluator: impl Fn(&T) -> (bool, String) + Send + Sync + 'static,
) -> Result<Self, Error>
pub fn explain_with( name: impl Into<String>, evaluator: impl Fn(&T) -> (bool, String) + Send + Sync + 'static, ) -> Result<Self, Error>
Creates a leaf policy whose predicate also explains each result.
Sourcepub fn all(
name: impl Into<String>,
policies: impl IntoIterator<Item = Self>,
) -> Result<Self, Error>
pub fn all( name: impl Into<String>, policies: impl IntoIterator<Item = Self>, ) -> Result<Self, Error>
Creates a policy that accepts only when every child accepts.
All children are evaluated so the returned tree contains a complete explanation rather than stopping at the first rejection.
Sourcepub fn any(
name: impl Into<String>,
policies: impl IntoIterator<Item = Self>,
) -> Result<Self, Error>
pub fn any( name: impl Into<String>, policies: impl IntoIterator<Item = Self>, ) -> Result<Self, Error>
Creates a policy that accepts when at least one child accepts. All children are evaluated for a complete explanation.
Sourcepub fn not(self, name: impl Into<String>) -> Result<Self, Error>
pub fn not(self, name: impl Into<String>) -> Result<Self, Error>
Creates a policy with the opposite result of this policy.
Source§impl<T> Policy<T>
impl<T> Policy<T>
Source§impl Policy<f64>
impl Policy<f64>
Sourcepub fn absolute_tolerance(
name: impl Into<String>,
target: f64,
tolerance: f64,
) -> Result<Self, Error>
pub fn absolute_tolerance( name: impl Into<String>, target: f64, tolerance: f64, ) -> Result<Self, Error>
Accepts finite values within an absolute distance of a finite target.
Sourcepub fn relative_tolerance(
name: impl Into<String>,
target: f64,
fraction: f64,
absolute_floor: f64,
) -> Result<Self, Error>
pub fn relative_tolerance( name: impl Into<String>, target: f64, fraction: f64, absolute_floor: f64, ) -> Result<Self, Error>
Accepts finite values within a fraction of a finite target.
absolute_floor prevents a zero or tiny target from creating an
unusably small tolerance. The effective tolerance is the greater of
abs(target) * fraction and absolute_floor.