pub struct RcBiPredicate<T, U> { /* private fields */ }Expand description
An Rc-based bi-predicate with single-threaded shared ownership.
This type is suitable for scenarios where the bi-predicate needs
to be reused in a single-threaded context. Composition methods
borrow &self, allowing the original bi-predicate to remain
usable after composition.
§Examples
use prism3_function::bi_predicate::{BiPredicate, RcBiPredicate};
let pred = RcBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
assert!(pred.test(&5, &3));
// Original bi-predicate remains usable after composition
let combined = pred.and(RcBiPredicate::new(|x, y| x > y));
assert!(pred.test(&5, &3)); // Still works§Author
Haixing Hu
Implementations§
Source§impl<T: 'static, U: 'static> RcBiPredicate<T, U>
impl<T: 'static, U: 'static> RcBiPredicate<T, U>
Sourcepub fn new<F>(f: F) -> Self
pub fn new<F>(f: F) -> Self
Creates a new bi-predicate.
Wraps the provided closure in the appropriate smart pointer type for this bi-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 bi-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 bi-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
Creates a bi-predicate that always returns true.
§Returns
A new RcBiPredicate that always returns true.
Sourcepub fn always_false() -> Self
pub fn always_false() -> Self
Creates a bi-predicate that always returns false.
§Returns
A new RcBiPredicate that always returns false.
Sourcepub fn and<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
pub fn and<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
Sourcepub fn or<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
pub fn or<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
Sourcepub fn not(&self) -> RcBiPredicate<T, U>
pub fn not(&self) -> RcBiPredicate<T, U>
Returns a bi-predicate that represents the logical negation of this bi-predicate.
This method consumes self due to single-ownership semantics.
§Returns
A new bi-predicate representing the logical negation.
Sourcepub fn nand<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
pub fn nand<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
Returns a bi-predicate that represents the logical NAND (NOT AND) of this bi-predicate and another.
NAND returns true unless both bi-predicates are true.
Equivalent to !(self AND other).
This method consumes self due to single-ownership semantics.
§Parameters
other- The other bi-predicate to combine with.
§Returns
A new bi-predicate representing the logical NAND.
Sourcepub fn xor<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
pub fn xor<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
Returns a bi-predicate that represents the logical XOR (exclusive OR) of this bi-predicate and another.
XOR returns true if exactly one of the bi-predicates is
true.
This method consumes self due to single-ownership semantics.
§Parameters
other- The other bi-predicate to combine with.
§Returns
A new bi-predicate representing the logical XOR.
Sourcepub fn nor<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
pub fn nor<P>(&self, other: P) -> RcBiPredicate<T, U>where
P: BiPredicate<T, U> + 'static,
Returns a bi-predicate that represents the logical NOR (NOT OR) of this bi-predicate and another.
NOR returns true only when both bi-predicates are false.
Equivalent to !(self OR other).
This method consumes self due to single-ownership semantics.
§Parameters
other- The other bi-predicate to combine with.
§Returns
A new bi-predicate representing the logical NOR.
Trait Implementations§
Source§impl<T, U> BiPredicate<T, U> for RcBiPredicate<T, U>
impl<T, U> BiPredicate<T, U> for RcBiPredicate<T, U>
Source§fn test(&self, first: &T, second: &U) -> bool
fn test(&self, first: &T, second: &U) -> bool
Source§fn into_box(self) -> BoxBiPredicate<T, U>where
T: 'static,
U: 'static,
fn into_box(self) -> BoxBiPredicate<T, U>where
T: 'static,
U: 'static,
BoxBiPredicate. Read moreSource§fn into_rc(self) -> RcBiPredicate<T, U>where
T: 'static,
U: 'static,
fn into_rc(self) -> RcBiPredicate<T, U>where
T: 'static,
U: 'static,
RcBiPredicate. Read moreSource§fn into_fn(self) -> impl Fn(&T, &U) -> bool
fn into_fn(self) -> impl Fn(&T, &U) -> bool
fn to_box(&self) -> BoxBiPredicate<T, U>where
T: 'static,
U: 'static,
fn to_rc(&self) -> RcBiPredicate<T, U>where
T: 'static,
U: 'static,
fn to_fn(&self) -> impl Fn(&T, &U) -> bool
Source§fn into_arc(self) -> ArcBiPredicate<T, U>
fn into_arc(self) -> ArcBiPredicate<T, U>
ArcBiPredicate. Read more