pub struct BoxPredicate<T> { /* private fields */ }Expand description
A Box-based predicate with single ownership.
This type is suitable for one-time use scenarios where the predicate does
not need to be cloned or shared. Composition methods consume self,
reflecting the single-ownership model.
§Examples
use prism3_function::predicate::{Predicate, BoxPredicate};
let pred = BoxPredicate::new(|x: &i32| *x > 0);
assert!(pred.test(&5));
// Chaining consumes the predicate
let combined = pred.and(BoxPredicate::new(|x| x % 2 == 0));
assert!(combined.test(&4));§Author
Haixing Hu
Implementations§
Source§impl<T: 'static> BoxPredicate<T>
impl<T: 'static> BoxPredicate<T>
Sourcepub fn new<F>(f: F) -> Self
pub fn new<F>(f: F) -> Self
Creates a new predicate.
Wraps the provided closure in the appropriate smart pointer type for this predicate implementation.
Sourcepub fn new_with_name<F>(name: &str, f: F) -> Self
pub fn new_with_name<F>(name: &str, f: F) -> Self
Creates a new named predicate.
Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.
Sourcepub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Self
pub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Self
Creates a new named predicate with an optional name.
Wraps the provided closure and assigns it an optional name.
Sourcepub fn always_true() -> Self
pub fn always_true() -> Self
Sourcepub fn always_false() -> Self
pub fn always_false() -> Self
Creates a predicate that always returns false.
§Returns
A new BoxPredicate that always returns false.
Sourcepub fn and<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
pub fn and<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
Sourcepub fn or<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
pub fn or<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
Sourcepub fn not(self) -> BoxPredicate<T>where
T: 'static,
pub fn not(self) -> BoxPredicate<T>where
T: 'static,
Returns a predicate that represents the logical negation of this predicate.
This method consumes self due to single-ownership semantics.
§Returns
A new predicate representing the logical negation.
Sourcepub fn nand<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
pub fn nand<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
Returns a predicate that represents the logical NAND (NOT AND) of this predicate and another.
NAND returns true unless both predicates are true.
Equivalent to !(self AND other).
This method consumes self due to single-ownership semantics.
§Parameters
other- The other predicate to combine with.
§Returns
A new predicate representing the logical NAND.
Sourcepub fn xor<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
pub fn xor<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
Returns a predicate that represents the logical XOR (exclusive OR) of this predicate and another.
XOR returns true if exactly one of the predicates is true.
This method consumes self due to single-ownership semantics.
§Parameters
other- The other predicate to combine with.
§Returns
A new predicate representing the logical XOR.
Sourcepub fn nor<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
pub fn nor<P>(self, other: P) -> BoxPredicate<T>where
P: Predicate<T> + 'static,
T: 'static,
Returns a predicate that represents the logical NOR (NOT OR) of this predicate and another.
NOR returns true only when both predicates are false.
Equivalent to !(self OR other).
This method consumes self due to single-ownership semantics.
§Parameters
other- The other predicate to combine with.
§Returns
A new predicate representing the logical NOR.
Trait Implementations§
Source§impl<T> Debug for BoxPredicate<T>
impl<T> Debug for BoxPredicate<T>
Source§impl<T> Display for BoxPredicate<T>
impl<T> Display for BoxPredicate<T>
Source§impl<T: 'static> Predicate<T> for BoxPredicate<T>
impl<T: 'static> Predicate<T> for BoxPredicate<T>
Source§fn test(&self, value: &T) -> bool
fn test(&self, value: &T) -> bool
Source§fn into_box(self) -> BoxPredicate<T>where
T: 'static,
fn into_box(self) -> BoxPredicate<T>where
T: 'static,
BoxPredicate. Read moreSource§fn into_rc(self) -> RcPredicate<T>where
T: 'static,
fn into_rc(self) -> RcPredicate<T>where
T: 'static,
RcPredicate. Read more