asserting/predicate/
mod.rs

1//! Implementation of the predicate assertion.
2
3use crate::expectations::Predicate;
4use crate::spec::{Expectation, Expression};
5#[cfg(not(feature = "std"))]
6use alloc::{format, string::String};
7
8impl<S, P> Expectation<S> for Predicate<P>
9where
10    P: Fn(&S) -> bool,
11{
12    fn test(&mut self, subject: &S) -> bool {
13        (self.predicate)(subject)
14    }
15
16    fn message(&self, expression: Expression<'_>, _actual: &S) -> String {
17        self.message.clone().unwrap_or_else(|| {
18            format!("expected {expression} to satisfy the given predicate, but returned false")
19        })
20    }
21}
22
23#[cfg(test)]
24mod tests;