pub struct RcPredicate<T> { /* private fields */ }Expand description
An Rc-based predicate with single-threaded shared ownership.
This type is suitable for scenarios where the predicate needs to be
reused in a single-threaded context. Composition methods borrow &self,
allowing the original predicate to remain usable after composition.
§Examples
use prism3_function::predicate::{Predicate, RcPredicate};
let pred = RcPredicate::new(|x: &i32| *x > 0);
assert!(pred.test(&5));
// Original predicate remains usable after composition
let combined = pred.and(RcPredicate::new(|x| x % 2 == 0));
assert!(pred.test(&5)); // Still works§Author
Haixing Hu
Implementations§
Source§impl<T: 'static> RcPredicate<T>
impl<T: 'static> RcPredicate<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 RcPredicate that always returns false.
Sourcepub fn and<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<T> + 'static,
pub fn and<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<T> + 'static,
Sourcepub fn or<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<T> + 'static,
pub fn or<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<T> + 'static,
Sourcepub fn not(&self) -> RcPredicate<T>
pub fn not(&self) -> RcPredicate<T>
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) -> RcPredicate<T>where
P: Predicate<T> + 'static,
pub fn nand<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<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) -> RcPredicate<T>where
P: Predicate<T> + 'static,
pub fn xor<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<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) -> RcPredicate<T>where
P: Predicate<T> + 'static,
pub fn nor<P>(&self, other: P) -> RcPredicate<T>where
P: Predicate<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> Clone for RcPredicate<T>
impl<T> Clone for RcPredicate<T>
Source§impl<T> Debug for RcPredicate<T>
impl<T> Debug for RcPredicate<T>
Source§impl<T> Display for RcPredicate<T>
impl<T> Display for RcPredicate<T>
Source§impl<T: 'static> Predicate<T> for RcPredicate<T>
impl<T: 'static> Predicate<T> for RcPredicate<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 moreSource§fn into_fn(self) -> impl Fn(&T) -> bool
fn into_fn(self) -> impl Fn(&T) -> bool
Source§fn to_box(&self) -> BoxPredicate<T>where
T: 'static,
fn to_box(&self) -> BoxPredicate<T>where
T: 'static,
BoxPredicate. Read moreSource§fn to_rc(&self) -> RcPredicate<T>where
T: 'static,
fn to_rc(&self) -> RcPredicate<T>where
T: 'static,
RcPredicate. Read moreSource§fn to_fn(&self) -> impl Fn(&T) -> bool
fn to_fn(&self) -> impl Fn(&T) -> bool
Source§fn into_arc(self) -> ArcPredicate<T>
fn into_arc(self) -> ArcPredicate<T>
ArcPredicate. Read more