pub struct ArcBiPredicate<T, U> { /* private fields */ }Expand description
An Arc-based bi-predicate with thread-safe shared ownership.
This type is suitable for scenarios where the bi-predicate needs
to be shared across threads. Composition methods borrow &self,
allowing the original bi-predicate to remain usable after
composition.
§Examples
use prism3_function::bi_predicate::{BiPredicate, ArcBiPredicate};
let pred = ArcBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
assert!(pred.test(&5, &3));
// Original bi-predicate remains usable after composition
let combined = pred.and(ArcBiPredicate::new(|x, y| x > y));
assert!(pred.test(&5, &3)); // Still works
// Can be cloned and sent across threads
let pred_clone = pred.clone();
std::thread::spawn(move || {
assert!(pred_clone.test(&10, &5));
}).join().unwrap();§Author
Haixing Hu
Implementations§
Source§impl<T: 'static, U: 'static> ArcBiPredicate<T, U>
impl<T: 'static, U: 'static> ArcBiPredicate<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 ArcBiPredicate 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 ArcBiPredicate that always returns false.
Sourcepub fn and<P>(&self, other: P) -> ArcBiPredicate<T, U>
pub fn and<P>(&self, other: P) -> ArcBiPredicate<T, U>
Sourcepub fn or<P>(&self, other: P) -> ArcBiPredicate<T, U>
pub fn or<P>(&self, other: P) -> ArcBiPredicate<T, U>
Sourcepub fn not(&self) -> ArcBiPredicate<T, U>
pub fn not(&self) -> ArcBiPredicate<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) -> ArcBiPredicate<T, U>
pub fn nand<P>(&self, other: P) -> ArcBiPredicate<T, U>
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) -> ArcBiPredicate<T, U>
pub fn xor<P>(&self, other: P) -> ArcBiPredicate<T, U>
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) -> ArcBiPredicate<T, U>
pub fn nor<P>(&self, other: P) -> ArcBiPredicate<T, U>
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: 'static, U: 'static> BiPredicate<T, U> for ArcBiPredicate<T, U>
impl<T: 'static, U: 'static> BiPredicate<T, U> for ArcBiPredicate<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_arc(self) -> ArcBiPredicate<T, U>where
T: 'static,
U: 'static,
fn into_arc(self) -> ArcBiPredicate<T, U>where
T: 'static,
U: 'static,
ArcBiPredicate. Read more