BoxBiPredicate

Struct BoxBiPredicate 

Source
pub struct BoxBiPredicate<T, U> { /* private fields */ }
Expand description

A Box-based bi-predicate with single ownership.

This type is suitable for one-time use scenarios where the bi-predicate does not need to be cloned or shared. Composition methods consume self, reflecting the single-ownership model.

§Examples

use prism3_function::bi_predicate::{BiPredicate, BoxBiPredicate};

let pred = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
assert!(pred.test(&5, &3));

// Chaining consumes the bi-predicate
let combined = pred.and(BoxBiPredicate::new(|x, y| x > y));
assert!(combined.test(&10, &5));

§Author

Haixing Hu

Implementations§

Source§

impl<T, U> BoxBiPredicate<T, U>

Source

pub fn new<F>(f: F) -> Self
where F: Fn(&T, &U) -> bool + 'static,

Creates a new BoxBiPredicate from a closure.

§Parameters
  • f - The closure to wrap.
§Returns

A new BoxBiPredicate instance.

Examples found in repository?
examples/always_bi_predicate_demo.rs (line 89)
11fn main() {
12    println!("=== BoxBiPredicate always_true/always_false Demo ===\n");
13
14    // BoxBiPredicate::always_true
15    let always_true: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
16    println!("BoxBiPredicate::always_true():");
17    println!("  test(&42, &10): {}", always_true.test(&42, &10));
18    println!("  test(&-1, &5): {}", always_true.test(&-1, &5));
19    println!("  test(&0, &0): {}", always_true.test(&0, &0));
20    println!("  name: {:?}", always_true.name());
21
22    // BoxBiPredicate::always_false
23    let always_false: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
24    println!("\nBoxBiPredicate::always_false():");
25    println!("  test(&42, &10): {}", always_false.test(&42, &10));
26    println!("  test(&-1, &5): {}", always_false.test(&-1, &5));
27    println!("  test(&0, &0): {}", always_false.test(&0, &0));
28    println!("  name: {:?}", always_false.name());
29
30    println!("\n=== RcBiPredicate always_true/always_false Demo ===\n");
31
32    // RcBiPredicate::always_true
33    let rc_always_true: RcBiPredicate<String, i32> = RcBiPredicate::always_true();
34    println!("RcBiPredicate::always_true():");
35    println!(
36        "  test(&\"hello\", &5): {}",
37        rc_always_true.test(&"hello".to_string(), &5)
38    );
39    println!(
40        "  test(&\"world\", &-3): {}",
41        rc_always_true.test(&"world".to_string(), &-3)
42    );
43    println!("  name: {:?}", rc_always_true.name());
44
45    // RcBiPredicate::always_false
46    let rc_always_false: RcBiPredicate<String, i32> = RcBiPredicate::always_false();
47    println!("\nRcBiPredicate::always_false():");
48    println!(
49        "  test(&\"hello\", &5): {}",
50        rc_always_false.test(&"hello".to_string(), &5)
51    );
52    println!(
53        "  test(&\"world\", &-3): {}",
54        rc_always_false.test(&"world".to_string(), &-3)
55    );
56    println!("  name: {:?}", rc_always_false.name());
57
58    // Can be cloned and reused
59    let rc_clone = rc_always_true.clone();
60    println!("\nAfter cloning, still usable:");
61    println!(
62        "  Original: test(&\"test\", &1): {}",
63        rc_always_true.test(&"test".to_string(), &1)
64    );
65    println!(
66        "  Clone: test(&\"test\", &2): {}",
67        rc_clone.test(&"test".to_string(), &2)
68    );
69
70    println!("\n=== ArcBiPredicate always_true/always_false Demo ===\n");
71
72    // ArcBiPredicate::always_true
73    let arc_always_true: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_true();
74    println!("ArcBiPredicate::always_true():");
75    println!("  test(&100, &50): {}", arc_always_true.test(&100, &50));
76    println!("  test(&-100, &25): {}", arc_always_true.test(&-100, &25));
77    println!("  name: {:?}", arc_always_true.name());
78
79    // ArcBiPredicate::always_false
80    let arc_always_false: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_false();
81    println!("\nArcBiPredicate::always_false():");
82    println!("  test(&100, &50): {}", arc_always_false.test(&100, &50));
83    println!("  test(&-100, &25): {}", arc_always_false.test(&-100, &25));
84    println!("  name: {:?}", arc_always_false.name());
85
86    println!("\n=== Combining with other bi-predicates ===\n");
87
88    // Combining with always_true (AND)
89    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
90    let combined_and_true = sum_positive.and(BoxBiPredicate::always_true());
91    println!("sum_positive AND always_true:");
92    println!(
93        "  test(&5, &3): {} (equivalent to sum_positive)",
94        combined_and_true.test(&5, &3)
95    );
96    println!(
97        "  test(&-3, &-5): {} (equivalent to sum_positive)",
98        combined_and_true.test(&-3, &-5)
99    );
100
101    // Combining with always_false (AND)
102    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
103    let combined_and_false = sum_positive.and(BoxBiPredicate::always_false());
104    println!("\nsum_positive AND always_false:");
105    println!(
106        "  test(&5, &3): {} (always false)",
107        combined_and_false.test(&5, &3)
108    );
109    println!(
110        "  test(&-3, &-5): {} (always false)",
111        combined_and_false.test(&-3, &-5)
112    );
113
114    // Combining with always_true (OR)
115    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
116    let combined_or_true = sum_positive.or(BoxBiPredicate::always_true());
117    println!("\nsum_positive OR always_true:");
118    println!(
119        "  test(&5, &3): {} (always true)",
120        combined_or_true.test(&5, &3)
121    );
122    println!(
123        "  test(&-3, &-5): {} (always true)",
124        combined_or_true.test(&-3, &-5)
125    );
126
127    // Combining with always_false (OR)
128    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
129    let combined_or_false = sum_positive.or(BoxBiPredicate::always_false());
130    println!("\nsum_positive OR always_false:");
131    println!(
132        "  test(&5, &3): {} (equivalent to sum_positive)",
133        combined_or_false.test(&5, &3)
134    );
135    println!(
136        "  test(&-3, &-5): {} (equivalent to sum_positive)",
137        combined_or_false.test(&-3, &-5)
138    );
139
140    println!("\n=== Practical scenarios: Default pass/reject filters ===\n");
141
142    // Scenario 1: Default pass-all filter
143    let pairs = vec![(1, 2), (3, 4), (5, 6)];
144    let pass_all = BoxBiPredicate::<i32, i32>::always_true();
145    let closure = pass_all.into_fn();
146    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
147    println!("Default pass all elements: {:?} -> {:?}", pairs, filtered);
148
149    // Scenario 2: Default reject-all filter
150    let pairs = vec![(1, 2), (3, 4), (5, 6)];
151    let reject_all = BoxBiPredicate::<i32, i32>::always_false();
152    let closure = reject_all.into_fn();
153    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
154    println!("Default reject all elements: {:?} -> {:?}", pairs, filtered);
155
156    // Scenario 3: Configurable filter
157    fn configurable_filter(enable_filter: bool) -> BoxBiPredicate<i32, i32> {
158        if enable_filter {
159            BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 5)
160        } else {
161            BoxBiPredicate::always_true()
162        }
163    }
164
165    let pairs = vec![(1, 2), (3, 4), (5, 6)];
166
167    let filter_enabled = configurable_filter(true);
168    let closure = filter_enabled.into_fn();
169    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
170    println!("\nFilter enabled: {:?} -> {:?}", pairs, filtered);
171
172    let filter_disabled = configurable_filter(false);
173    let closure = filter_disabled.into_fn();
174    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
175    println!("Filter disabled: {:?} -> {:?}", pairs, filtered);
176}
Source

pub fn new_with_name<F>(name: &str, f: F) -> Self
where F: Fn(&T, &U) -> bool + 'static,

Creates a named BoxBiPredicate from a closure.

§Parameters
  • name - The name for this bi-predicate.
  • f - The closure to wrap.
§Returns

A new named BoxBiPredicate instance.

Source

pub fn always_true() -> Self

Creates a bi-predicate that always returns true.

§Returns

A new BoxBiPredicate that always returns true.

§Examples
use prism3_function::bi_predicate::{BiPredicate, BoxBiPredicate};

let pred: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
assert!(pred.test(&42, &10));
assert!(pred.test(&-1, &5));
assert!(pred.test(&0, &0));
Examples found in repository?
examples/always_bi_predicate_demo.rs (line 15)
11fn main() {
12    println!("=== BoxBiPredicate always_true/always_false Demo ===\n");
13
14    // BoxBiPredicate::always_true
15    let always_true: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
16    println!("BoxBiPredicate::always_true():");
17    println!("  test(&42, &10): {}", always_true.test(&42, &10));
18    println!("  test(&-1, &5): {}", always_true.test(&-1, &5));
19    println!("  test(&0, &0): {}", always_true.test(&0, &0));
20    println!("  name: {:?}", always_true.name());
21
22    // BoxBiPredicate::always_false
23    let always_false: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
24    println!("\nBoxBiPredicate::always_false():");
25    println!("  test(&42, &10): {}", always_false.test(&42, &10));
26    println!("  test(&-1, &5): {}", always_false.test(&-1, &5));
27    println!("  test(&0, &0): {}", always_false.test(&0, &0));
28    println!("  name: {:?}", always_false.name());
29
30    println!("\n=== RcBiPredicate always_true/always_false Demo ===\n");
31
32    // RcBiPredicate::always_true
33    let rc_always_true: RcBiPredicate<String, i32> = RcBiPredicate::always_true();
34    println!("RcBiPredicate::always_true():");
35    println!(
36        "  test(&\"hello\", &5): {}",
37        rc_always_true.test(&"hello".to_string(), &5)
38    );
39    println!(
40        "  test(&\"world\", &-3): {}",
41        rc_always_true.test(&"world".to_string(), &-3)
42    );
43    println!("  name: {:?}", rc_always_true.name());
44
45    // RcBiPredicate::always_false
46    let rc_always_false: RcBiPredicate<String, i32> = RcBiPredicate::always_false();
47    println!("\nRcBiPredicate::always_false():");
48    println!(
49        "  test(&\"hello\", &5): {}",
50        rc_always_false.test(&"hello".to_string(), &5)
51    );
52    println!(
53        "  test(&\"world\", &-3): {}",
54        rc_always_false.test(&"world".to_string(), &-3)
55    );
56    println!("  name: {:?}", rc_always_false.name());
57
58    // Can be cloned and reused
59    let rc_clone = rc_always_true.clone();
60    println!("\nAfter cloning, still usable:");
61    println!(
62        "  Original: test(&\"test\", &1): {}",
63        rc_always_true.test(&"test".to_string(), &1)
64    );
65    println!(
66        "  Clone: test(&\"test\", &2): {}",
67        rc_clone.test(&"test".to_string(), &2)
68    );
69
70    println!("\n=== ArcBiPredicate always_true/always_false Demo ===\n");
71
72    // ArcBiPredicate::always_true
73    let arc_always_true: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_true();
74    println!("ArcBiPredicate::always_true():");
75    println!("  test(&100, &50): {}", arc_always_true.test(&100, &50));
76    println!("  test(&-100, &25): {}", arc_always_true.test(&-100, &25));
77    println!("  name: {:?}", arc_always_true.name());
78
79    // ArcBiPredicate::always_false
80    let arc_always_false: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_false();
81    println!("\nArcBiPredicate::always_false():");
82    println!("  test(&100, &50): {}", arc_always_false.test(&100, &50));
83    println!("  test(&-100, &25): {}", arc_always_false.test(&-100, &25));
84    println!("  name: {:?}", arc_always_false.name());
85
86    println!("\n=== Combining with other bi-predicates ===\n");
87
88    // Combining with always_true (AND)
89    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
90    let combined_and_true = sum_positive.and(BoxBiPredicate::always_true());
91    println!("sum_positive AND always_true:");
92    println!(
93        "  test(&5, &3): {} (equivalent to sum_positive)",
94        combined_and_true.test(&5, &3)
95    );
96    println!(
97        "  test(&-3, &-5): {} (equivalent to sum_positive)",
98        combined_and_true.test(&-3, &-5)
99    );
100
101    // Combining with always_false (AND)
102    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
103    let combined_and_false = sum_positive.and(BoxBiPredicate::always_false());
104    println!("\nsum_positive AND always_false:");
105    println!(
106        "  test(&5, &3): {} (always false)",
107        combined_and_false.test(&5, &3)
108    );
109    println!(
110        "  test(&-3, &-5): {} (always false)",
111        combined_and_false.test(&-3, &-5)
112    );
113
114    // Combining with always_true (OR)
115    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
116    let combined_or_true = sum_positive.or(BoxBiPredicate::always_true());
117    println!("\nsum_positive OR always_true:");
118    println!(
119        "  test(&5, &3): {} (always true)",
120        combined_or_true.test(&5, &3)
121    );
122    println!(
123        "  test(&-3, &-5): {} (always true)",
124        combined_or_true.test(&-3, &-5)
125    );
126
127    // Combining with always_false (OR)
128    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
129    let combined_or_false = sum_positive.or(BoxBiPredicate::always_false());
130    println!("\nsum_positive OR always_false:");
131    println!(
132        "  test(&5, &3): {} (equivalent to sum_positive)",
133        combined_or_false.test(&5, &3)
134    );
135    println!(
136        "  test(&-3, &-5): {} (equivalent to sum_positive)",
137        combined_or_false.test(&-3, &-5)
138    );
139
140    println!("\n=== Practical scenarios: Default pass/reject filters ===\n");
141
142    // Scenario 1: Default pass-all filter
143    let pairs = vec![(1, 2), (3, 4), (5, 6)];
144    let pass_all = BoxBiPredicate::<i32, i32>::always_true();
145    let closure = pass_all.into_fn();
146    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
147    println!("Default pass all elements: {:?} -> {:?}", pairs, filtered);
148
149    // Scenario 2: Default reject-all filter
150    let pairs = vec![(1, 2), (3, 4), (5, 6)];
151    let reject_all = BoxBiPredicate::<i32, i32>::always_false();
152    let closure = reject_all.into_fn();
153    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
154    println!("Default reject all elements: {:?} -> {:?}", pairs, filtered);
155
156    // Scenario 3: Configurable filter
157    fn configurable_filter(enable_filter: bool) -> BoxBiPredicate<i32, i32> {
158        if enable_filter {
159            BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 5)
160        } else {
161            BoxBiPredicate::always_true()
162        }
163    }
164
165    let pairs = vec![(1, 2), (3, 4), (5, 6)];
166
167    let filter_enabled = configurable_filter(true);
168    let closure = filter_enabled.into_fn();
169    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
170    println!("\nFilter enabled: {:?} -> {:?}", pairs, filtered);
171
172    let filter_disabled = configurable_filter(false);
173    let closure = filter_disabled.into_fn();
174    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
175    println!("Filter disabled: {:?} -> {:?}", pairs, filtered);
176}
Source

pub fn always_false() -> Self

Creates a bi-predicate that always returns false.

§Returns

A new BoxBiPredicate that always returns false.

§Examples
use prism3_function::bi_predicate::{BiPredicate, BoxBiPredicate};

let pred: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
assert!(!pred.test(&42, &10));
assert!(!pred.test(&-1, &5));
assert!(!pred.test(&0, &0));
Examples found in repository?
examples/always_bi_predicate_demo.rs (line 23)
11fn main() {
12    println!("=== BoxBiPredicate always_true/always_false Demo ===\n");
13
14    // BoxBiPredicate::always_true
15    let always_true: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
16    println!("BoxBiPredicate::always_true():");
17    println!("  test(&42, &10): {}", always_true.test(&42, &10));
18    println!("  test(&-1, &5): {}", always_true.test(&-1, &5));
19    println!("  test(&0, &0): {}", always_true.test(&0, &0));
20    println!("  name: {:?}", always_true.name());
21
22    // BoxBiPredicate::always_false
23    let always_false: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
24    println!("\nBoxBiPredicate::always_false():");
25    println!("  test(&42, &10): {}", always_false.test(&42, &10));
26    println!("  test(&-1, &5): {}", always_false.test(&-1, &5));
27    println!("  test(&0, &0): {}", always_false.test(&0, &0));
28    println!("  name: {:?}", always_false.name());
29
30    println!("\n=== RcBiPredicate always_true/always_false Demo ===\n");
31
32    // RcBiPredicate::always_true
33    let rc_always_true: RcBiPredicate<String, i32> = RcBiPredicate::always_true();
34    println!("RcBiPredicate::always_true():");
35    println!(
36        "  test(&\"hello\", &5): {}",
37        rc_always_true.test(&"hello".to_string(), &5)
38    );
39    println!(
40        "  test(&\"world\", &-3): {}",
41        rc_always_true.test(&"world".to_string(), &-3)
42    );
43    println!("  name: {:?}", rc_always_true.name());
44
45    // RcBiPredicate::always_false
46    let rc_always_false: RcBiPredicate<String, i32> = RcBiPredicate::always_false();
47    println!("\nRcBiPredicate::always_false():");
48    println!(
49        "  test(&\"hello\", &5): {}",
50        rc_always_false.test(&"hello".to_string(), &5)
51    );
52    println!(
53        "  test(&\"world\", &-3): {}",
54        rc_always_false.test(&"world".to_string(), &-3)
55    );
56    println!("  name: {:?}", rc_always_false.name());
57
58    // Can be cloned and reused
59    let rc_clone = rc_always_true.clone();
60    println!("\nAfter cloning, still usable:");
61    println!(
62        "  Original: test(&\"test\", &1): {}",
63        rc_always_true.test(&"test".to_string(), &1)
64    );
65    println!(
66        "  Clone: test(&\"test\", &2): {}",
67        rc_clone.test(&"test".to_string(), &2)
68    );
69
70    println!("\n=== ArcBiPredicate always_true/always_false Demo ===\n");
71
72    // ArcBiPredicate::always_true
73    let arc_always_true: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_true();
74    println!("ArcBiPredicate::always_true():");
75    println!("  test(&100, &50): {}", arc_always_true.test(&100, &50));
76    println!("  test(&-100, &25): {}", arc_always_true.test(&-100, &25));
77    println!("  name: {:?}", arc_always_true.name());
78
79    // ArcBiPredicate::always_false
80    let arc_always_false: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_false();
81    println!("\nArcBiPredicate::always_false():");
82    println!("  test(&100, &50): {}", arc_always_false.test(&100, &50));
83    println!("  test(&-100, &25): {}", arc_always_false.test(&-100, &25));
84    println!("  name: {:?}", arc_always_false.name());
85
86    println!("\n=== Combining with other bi-predicates ===\n");
87
88    // Combining with always_true (AND)
89    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
90    let combined_and_true = sum_positive.and(BoxBiPredicate::always_true());
91    println!("sum_positive AND always_true:");
92    println!(
93        "  test(&5, &3): {} (equivalent to sum_positive)",
94        combined_and_true.test(&5, &3)
95    );
96    println!(
97        "  test(&-3, &-5): {} (equivalent to sum_positive)",
98        combined_and_true.test(&-3, &-5)
99    );
100
101    // Combining with always_false (AND)
102    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
103    let combined_and_false = sum_positive.and(BoxBiPredicate::always_false());
104    println!("\nsum_positive AND always_false:");
105    println!(
106        "  test(&5, &3): {} (always false)",
107        combined_and_false.test(&5, &3)
108    );
109    println!(
110        "  test(&-3, &-5): {} (always false)",
111        combined_and_false.test(&-3, &-5)
112    );
113
114    // Combining with always_true (OR)
115    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
116    let combined_or_true = sum_positive.or(BoxBiPredicate::always_true());
117    println!("\nsum_positive OR always_true:");
118    println!(
119        "  test(&5, &3): {} (always true)",
120        combined_or_true.test(&5, &3)
121    );
122    println!(
123        "  test(&-3, &-5): {} (always true)",
124        combined_or_true.test(&-3, &-5)
125    );
126
127    // Combining with always_false (OR)
128    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
129    let combined_or_false = sum_positive.or(BoxBiPredicate::always_false());
130    println!("\nsum_positive OR always_false:");
131    println!(
132        "  test(&5, &3): {} (equivalent to sum_positive)",
133        combined_or_false.test(&5, &3)
134    );
135    println!(
136        "  test(&-3, &-5): {} (equivalent to sum_positive)",
137        combined_or_false.test(&-3, &-5)
138    );
139
140    println!("\n=== Practical scenarios: Default pass/reject filters ===\n");
141
142    // Scenario 1: Default pass-all filter
143    let pairs = vec![(1, 2), (3, 4), (5, 6)];
144    let pass_all = BoxBiPredicate::<i32, i32>::always_true();
145    let closure = pass_all.into_fn();
146    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
147    println!("Default pass all elements: {:?} -> {:?}", pairs, filtered);
148
149    // Scenario 2: Default reject-all filter
150    let pairs = vec![(1, 2), (3, 4), (5, 6)];
151    let reject_all = BoxBiPredicate::<i32, i32>::always_false();
152    let closure = reject_all.into_fn();
153    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
154    println!("Default reject all elements: {:?} -> {:?}", pairs, filtered);
155
156    // Scenario 3: Configurable filter
157    fn configurable_filter(enable_filter: bool) -> BoxBiPredicate<i32, i32> {
158        if enable_filter {
159            BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 5)
160        } else {
161            BoxBiPredicate::always_true()
162        }
163    }
164
165    let pairs = vec![(1, 2), (3, 4), (5, 6)];
166
167    let filter_enabled = configurable_filter(true);
168    let closure = filter_enabled.into_fn();
169    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
170    println!("\nFilter enabled: {:?} -> {:?}", pairs, filtered);
171
172    let filter_disabled = configurable_filter(false);
173    let closure = filter_disabled.into_fn();
174    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
175    println!("Filter disabled: {:?} -> {:?}", pairs, filtered);
176}
Source

pub fn name(&self) -> Option<&str>

Returns the name of this bi-predicate, if set.

§Returns

An Option containing the bi-predicate’s name.

Examples found in repository?
examples/always_bi_predicate_demo.rs (line 20)
11fn main() {
12    println!("=== BoxBiPredicate always_true/always_false Demo ===\n");
13
14    // BoxBiPredicate::always_true
15    let always_true: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
16    println!("BoxBiPredicate::always_true():");
17    println!("  test(&42, &10): {}", always_true.test(&42, &10));
18    println!("  test(&-1, &5): {}", always_true.test(&-1, &5));
19    println!("  test(&0, &0): {}", always_true.test(&0, &0));
20    println!("  name: {:?}", always_true.name());
21
22    // BoxBiPredicate::always_false
23    let always_false: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
24    println!("\nBoxBiPredicate::always_false():");
25    println!("  test(&42, &10): {}", always_false.test(&42, &10));
26    println!("  test(&-1, &5): {}", always_false.test(&-1, &5));
27    println!("  test(&0, &0): {}", always_false.test(&0, &0));
28    println!("  name: {:?}", always_false.name());
29
30    println!("\n=== RcBiPredicate always_true/always_false Demo ===\n");
31
32    // RcBiPredicate::always_true
33    let rc_always_true: RcBiPredicate<String, i32> = RcBiPredicate::always_true();
34    println!("RcBiPredicate::always_true():");
35    println!(
36        "  test(&\"hello\", &5): {}",
37        rc_always_true.test(&"hello".to_string(), &5)
38    );
39    println!(
40        "  test(&\"world\", &-3): {}",
41        rc_always_true.test(&"world".to_string(), &-3)
42    );
43    println!("  name: {:?}", rc_always_true.name());
44
45    // RcBiPredicate::always_false
46    let rc_always_false: RcBiPredicate<String, i32> = RcBiPredicate::always_false();
47    println!("\nRcBiPredicate::always_false():");
48    println!(
49        "  test(&\"hello\", &5): {}",
50        rc_always_false.test(&"hello".to_string(), &5)
51    );
52    println!(
53        "  test(&\"world\", &-3): {}",
54        rc_always_false.test(&"world".to_string(), &-3)
55    );
56    println!("  name: {:?}", rc_always_false.name());
57
58    // Can be cloned and reused
59    let rc_clone = rc_always_true.clone();
60    println!("\nAfter cloning, still usable:");
61    println!(
62        "  Original: test(&\"test\", &1): {}",
63        rc_always_true.test(&"test".to_string(), &1)
64    );
65    println!(
66        "  Clone: test(&\"test\", &2): {}",
67        rc_clone.test(&"test".to_string(), &2)
68    );
69
70    println!("\n=== ArcBiPredicate always_true/always_false Demo ===\n");
71
72    // ArcBiPredicate::always_true
73    let arc_always_true: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_true();
74    println!("ArcBiPredicate::always_true():");
75    println!("  test(&100, &50): {}", arc_always_true.test(&100, &50));
76    println!("  test(&-100, &25): {}", arc_always_true.test(&-100, &25));
77    println!("  name: {:?}", arc_always_true.name());
78
79    // ArcBiPredicate::always_false
80    let arc_always_false: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_false();
81    println!("\nArcBiPredicate::always_false():");
82    println!("  test(&100, &50): {}", arc_always_false.test(&100, &50));
83    println!("  test(&-100, &25): {}", arc_always_false.test(&-100, &25));
84    println!("  name: {:?}", arc_always_false.name());
85
86    println!("\n=== Combining with other bi-predicates ===\n");
87
88    // Combining with always_true (AND)
89    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
90    let combined_and_true = sum_positive.and(BoxBiPredicate::always_true());
91    println!("sum_positive AND always_true:");
92    println!(
93        "  test(&5, &3): {} (equivalent to sum_positive)",
94        combined_and_true.test(&5, &3)
95    );
96    println!(
97        "  test(&-3, &-5): {} (equivalent to sum_positive)",
98        combined_and_true.test(&-3, &-5)
99    );
100
101    // Combining with always_false (AND)
102    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
103    let combined_and_false = sum_positive.and(BoxBiPredicate::always_false());
104    println!("\nsum_positive AND always_false:");
105    println!(
106        "  test(&5, &3): {} (always false)",
107        combined_and_false.test(&5, &3)
108    );
109    println!(
110        "  test(&-3, &-5): {} (always false)",
111        combined_and_false.test(&-3, &-5)
112    );
113
114    // Combining with always_true (OR)
115    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
116    let combined_or_true = sum_positive.or(BoxBiPredicate::always_true());
117    println!("\nsum_positive OR always_true:");
118    println!(
119        "  test(&5, &3): {} (always true)",
120        combined_or_true.test(&5, &3)
121    );
122    println!(
123        "  test(&-3, &-5): {} (always true)",
124        combined_or_true.test(&-3, &-5)
125    );
126
127    // Combining with always_false (OR)
128    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
129    let combined_or_false = sum_positive.or(BoxBiPredicate::always_false());
130    println!("\nsum_positive OR always_false:");
131    println!(
132        "  test(&5, &3): {} (equivalent to sum_positive)",
133        combined_or_false.test(&5, &3)
134    );
135    println!(
136        "  test(&-3, &-5): {} (equivalent to sum_positive)",
137        combined_or_false.test(&-3, &-5)
138    );
139
140    println!("\n=== Practical scenarios: Default pass/reject filters ===\n");
141
142    // Scenario 1: Default pass-all filter
143    let pairs = vec![(1, 2), (3, 4), (5, 6)];
144    let pass_all = BoxBiPredicate::<i32, i32>::always_true();
145    let closure = pass_all.into_fn();
146    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
147    println!("Default pass all elements: {:?} -> {:?}", pairs, filtered);
148
149    // Scenario 2: Default reject-all filter
150    let pairs = vec![(1, 2), (3, 4), (5, 6)];
151    let reject_all = BoxBiPredicate::<i32, i32>::always_false();
152    let closure = reject_all.into_fn();
153    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
154    println!("Default reject all elements: {:?} -> {:?}", pairs, filtered);
155
156    // Scenario 3: Configurable filter
157    fn configurable_filter(enable_filter: bool) -> BoxBiPredicate<i32, i32> {
158        if enable_filter {
159            BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 5)
160        } else {
161            BoxBiPredicate::always_true()
162        }
163    }
164
165    let pairs = vec![(1, 2), (3, 4), (5, 6)];
166
167    let filter_enabled = configurable_filter(true);
168    let closure = filter_enabled.into_fn();
169    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
170    println!("\nFilter enabled: {:?} -> {:?}", pairs, filtered);
171
172    let filter_disabled = configurable_filter(false);
173    let closure = filter_disabled.into_fn();
174    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
175    println!("Filter disabled: {:?} -> {:?}", pairs, filtered);
176}
Source

pub fn set_name(&mut self, name: &str)

Sets the name of this bi-predicate.

§Parameters
  • name - The new name for this bi-predicate.
Source

pub fn and<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static, T: 'static, U: 'static,

Returns a bi-predicate that represents the logical AND of this bi-predicate and another.

This method consumes self due to single-ownership semantics.

§Parameters
  • other - The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implements Clone). Can be:
    • A closure: |x: &T, y: &U| -> bool
    • A function pointer: fn(&T, &U) -> bool
    • Another BoxBiPredicate<T, U>
    • An RcBiPredicate<T, U>
    • An ArcBiPredicate<T, U>
    • Any type implementing BiPredicate<T, U>
§Returns

A new BoxBiPredicate representing the logical AND.

Examples found in repository?
examples/always_bi_predicate_demo.rs (line 90)
11fn main() {
12    println!("=== BoxBiPredicate always_true/always_false Demo ===\n");
13
14    // BoxBiPredicate::always_true
15    let always_true: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
16    println!("BoxBiPredicate::always_true():");
17    println!("  test(&42, &10): {}", always_true.test(&42, &10));
18    println!("  test(&-1, &5): {}", always_true.test(&-1, &5));
19    println!("  test(&0, &0): {}", always_true.test(&0, &0));
20    println!("  name: {:?}", always_true.name());
21
22    // BoxBiPredicate::always_false
23    let always_false: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
24    println!("\nBoxBiPredicate::always_false():");
25    println!("  test(&42, &10): {}", always_false.test(&42, &10));
26    println!("  test(&-1, &5): {}", always_false.test(&-1, &5));
27    println!("  test(&0, &0): {}", always_false.test(&0, &0));
28    println!("  name: {:?}", always_false.name());
29
30    println!("\n=== RcBiPredicate always_true/always_false Demo ===\n");
31
32    // RcBiPredicate::always_true
33    let rc_always_true: RcBiPredicate<String, i32> = RcBiPredicate::always_true();
34    println!("RcBiPredicate::always_true():");
35    println!(
36        "  test(&\"hello\", &5): {}",
37        rc_always_true.test(&"hello".to_string(), &5)
38    );
39    println!(
40        "  test(&\"world\", &-3): {}",
41        rc_always_true.test(&"world".to_string(), &-3)
42    );
43    println!("  name: {:?}", rc_always_true.name());
44
45    // RcBiPredicate::always_false
46    let rc_always_false: RcBiPredicate<String, i32> = RcBiPredicate::always_false();
47    println!("\nRcBiPredicate::always_false():");
48    println!(
49        "  test(&\"hello\", &5): {}",
50        rc_always_false.test(&"hello".to_string(), &5)
51    );
52    println!(
53        "  test(&\"world\", &-3): {}",
54        rc_always_false.test(&"world".to_string(), &-3)
55    );
56    println!("  name: {:?}", rc_always_false.name());
57
58    // Can be cloned and reused
59    let rc_clone = rc_always_true.clone();
60    println!("\nAfter cloning, still usable:");
61    println!(
62        "  Original: test(&\"test\", &1): {}",
63        rc_always_true.test(&"test".to_string(), &1)
64    );
65    println!(
66        "  Clone: test(&\"test\", &2): {}",
67        rc_clone.test(&"test".to_string(), &2)
68    );
69
70    println!("\n=== ArcBiPredicate always_true/always_false Demo ===\n");
71
72    // ArcBiPredicate::always_true
73    let arc_always_true: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_true();
74    println!("ArcBiPredicate::always_true():");
75    println!("  test(&100, &50): {}", arc_always_true.test(&100, &50));
76    println!("  test(&-100, &25): {}", arc_always_true.test(&-100, &25));
77    println!("  name: {:?}", arc_always_true.name());
78
79    // ArcBiPredicate::always_false
80    let arc_always_false: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_false();
81    println!("\nArcBiPredicate::always_false():");
82    println!("  test(&100, &50): {}", arc_always_false.test(&100, &50));
83    println!("  test(&-100, &25): {}", arc_always_false.test(&-100, &25));
84    println!("  name: {:?}", arc_always_false.name());
85
86    println!("\n=== Combining with other bi-predicates ===\n");
87
88    // Combining with always_true (AND)
89    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
90    let combined_and_true = sum_positive.and(BoxBiPredicate::always_true());
91    println!("sum_positive AND always_true:");
92    println!(
93        "  test(&5, &3): {} (equivalent to sum_positive)",
94        combined_and_true.test(&5, &3)
95    );
96    println!(
97        "  test(&-3, &-5): {} (equivalent to sum_positive)",
98        combined_and_true.test(&-3, &-5)
99    );
100
101    // Combining with always_false (AND)
102    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
103    let combined_and_false = sum_positive.and(BoxBiPredicate::always_false());
104    println!("\nsum_positive AND always_false:");
105    println!(
106        "  test(&5, &3): {} (always false)",
107        combined_and_false.test(&5, &3)
108    );
109    println!(
110        "  test(&-3, &-5): {} (always false)",
111        combined_and_false.test(&-3, &-5)
112    );
113
114    // Combining with always_true (OR)
115    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
116    let combined_or_true = sum_positive.or(BoxBiPredicate::always_true());
117    println!("\nsum_positive OR always_true:");
118    println!(
119        "  test(&5, &3): {} (always true)",
120        combined_or_true.test(&5, &3)
121    );
122    println!(
123        "  test(&-3, &-5): {} (always true)",
124        combined_or_true.test(&-3, &-5)
125    );
126
127    // Combining with always_false (OR)
128    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
129    let combined_or_false = sum_positive.or(BoxBiPredicate::always_false());
130    println!("\nsum_positive OR always_false:");
131    println!(
132        "  test(&5, &3): {} (equivalent to sum_positive)",
133        combined_or_false.test(&5, &3)
134    );
135    println!(
136        "  test(&-3, &-5): {} (equivalent to sum_positive)",
137        combined_or_false.test(&-3, &-5)
138    );
139
140    println!("\n=== Practical scenarios: Default pass/reject filters ===\n");
141
142    // Scenario 1: Default pass-all filter
143    let pairs = vec![(1, 2), (3, 4), (5, 6)];
144    let pass_all = BoxBiPredicate::<i32, i32>::always_true();
145    let closure = pass_all.into_fn();
146    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
147    println!("Default pass all elements: {:?} -> {:?}", pairs, filtered);
148
149    // Scenario 2: Default reject-all filter
150    let pairs = vec![(1, 2), (3, 4), (5, 6)];
151    let reject_all = BoxBiPredicate::<i32, i32>::always_false();
152    let closure = reject_all.into_fn();
153    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
154    println!("Default reject all elements: {:?} -> {:?}", pairs, filtered);
155
156    // Scenario 3: Configurable filter
157    fn configurable_filter(enable_filter: bool) -> BoxBiPredicate<i32, i32> {
158        if enable_filter {
159            BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 5)
160        } else {
161            BoxBiPredicate::always_true()
162        }
163    }
164
165    let pairs = vec![(1, 2), (3, 4), (5, 6)];
166
167    let filter_enabled = configurable_filter(true);
168    let closure = filter_enabled.into_fn();
169    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
170    println!("\nFilter enabled: {:?} -> {:?}", pairs, filtered);
171
172    let filter_disabled = configurable_filter(false);
173    let closure = filter_disabled.into_fn();
174    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
175    println!("Filter disabled: {:?} -> {:?}", pairs, filtered);
176}
Source

pub fn or<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static, T: 'static, U: 'static,

Returns a bi-predicate that represents the logical OR of this bi-predicate and another.

This method consumes self due to single-ownership semantics.

§Parameters
  • other - The other bi-predicate to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implements Clone). Can be:
    • A closure: |x: &T, y: &U| -> bool
    • A function pointer: fn(&T, &U) -> bool
    • Another BoxBiPredicate<T, U>
    • An RcBiPredicate<T, U>
    • An ArcBiPredicate<T, U>
    • Any type implementing BiPredicate<T, U>
§Returns

A new BoxBiPredicate representing the logical OR.

Examples found in repository?
examples/always_bi_predicate_demo.rs (line 116)
11fn main() {
12    println!("=== BoxBiPredicate always_true/always_false Demo ===\n");
13
14    // BoxBiPredicate::always_true
15    let always_true: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_true();
16    println!("BoxBiPredicate::always_true():");
17    println!("  test(&42, &10): {}", always_true.test(&42, &10));
18    println!("  test(&-1, &5): {}", always_true.test(&-1, &5));
19    println!("  test(&0, &0): {}", always_true.test(&0, &0));
20    println!("  name: {:?}", always_true.name());
21
22    // BoxBiPredicate::always_false
23    let always_false: BoxBiPredicate<i32, i32> = BoxBiPredicate::always_false();
24    println!("\nBoxBiPredicate::always_false():");
25    println!("  test(&42, &10): {}", always_false.test(&42, &10));
26    println!("  test(&-1, &5): {}", always_false.test(&-1, &5));
27    println!("  test(&0, &0): {}", always_false.test(&0, &0));
28    println!("  name: {:?}", always_false.name());
29
30    println!("\n=== RcBiPredicate always_true/always_false Demo ===\n");
31
32    // RcBiPredicate::always_true
33    let rc_always_true: RcBiPredicate<String, i32> = RcBiPredicate::always_true();
34    println!("RcBiPredicate::always_true():");
35    println!(
36        "  test(&\"hello\", &5): {}",
37        rc_always_true.test(&"hello".to_string(), &5)
38    );
39    println!(
40        "  test(&\"world\", &-3): {}",
41        rc_always_true.test(&"world".to_string(), &-3)
42    );
43    println!("  name: {:?}", rc_always_true.name());
44
45    // RcBiPredicate::always_false
46    let rc_always_false: RcBiPredicate<String, i32> = RcBiPredicate::always_false();
47    println!("\nRcBiPredicate::always_false():");
48    println!(
49        "  test(&\"hello\", &5): {}",
50        rc_always_false.test(&"hello".to_string(), &5)
51    );
52    println!(
53        "  test(&\"world\", &-3): {}",
54        rc_always_false.test(&"world".to_string(), &-3)
55    );
56    println!("  name: {:?}", rc_always_false.name());
57
58    // Can be cloned and reused
59    let rc_clone = rc_always_true.clone();
60    println!("\nAfter cloning, still usable:");
61    println!(
62        "  Original: test(&\"test\", &1): {}",
63        rc_always_true.test(&"test".to_string(), &1)
64    );
65    println!(
66        "  Clone: test(&\"test\", &2): {}",
67        rc_clone.test(&"test".to_string(), &2)
68    );
69
70    println!("\n=== ArcBiPredicate always_true/always_false Demo ===\n");
71
72    // ArcBiPredicate::always_true
73    let arc_always_true: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_true();
74    println!("ArcBiPredicate::always_true():");
75    println!("  test(&100, &50): {}", arc_always_true.test(&100, &50));
76    println!("  test(&-100, &25): {}", arc_always_true.test(&-100, &25));
77    println!("  name: {:?}", arc_always_true.name());
78
79    // ArcBiPredicate::always_false
80    let arc_always_false: ArcBiPredicate<i32, i32> = ArcBiPredicate::always_false();
81    println!("\nArcBiPredicate::always_false():");
82    println!("  test(&100, &50): {}", arc_always_false.test(&100, &50));
83    println!("  test(&-100, &25): {}", arc_always_false.test(&-100, &25));
84    println!("  name: {:?}", arc_always_false.name());
85
86    println!("\n=== Combining with other bi-predicates ===\n");
87
88    // Combining with always_true (AND)
89    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
90    let combined_and_true = sum_positive.and(BoxBiPredicate::always_true());
91    println!("sum_positive AND always_true:");
92    println!(
93        "  test(&5, &3): {} (equivalent to sum_positive)",
94        combined_and_true.test(&5, &3)
95    );
96    println!(
97        "  test(&-3, &-5): {} (equivalent to sum_positive)",
98        combined_and_true.test(&-3, &-5)
99    );
100
101    // Combining with always_false (AND)
102    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
103    let combined_and_false = sum_positive.and(BoxBiPredicate::always_false());
104    println!("\nsum_positive AND always_false:");
105    println!(
106        "  test(&5, &3): {} (always false)",
107        combined_and_false.test(&5, &3)
108    );
109    println!(
110        "  test(&-3, &-5): {} (always false)",
111        combined_and_false.test(&-3, &-5)
112    );
113
114    // Combining with always_true (OR)
115    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
116    let combined_or_true = sum_positive.or(BoxBiPredicate::always_true());
117    println!("\nsum_positive OR always_true:");
118    println!(
119        "  test(&5, &3): {} (always true)",
120        combined_or_true.test(&5, &3)
121    );
122    println!(
123        "  test(&-3, &-5): {} (always true)",
124        combined_or_true.test(&-3, &-5)
125    );
126
127    // Combining with always_false (OR)
128    let sum_positive = BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 0);
129    let combined_or_false = sum_positive.or(BoxBiPredicate::always_false());
130    println!("\nsum_positive OR always_false:");
131    println!(
132        "  test(&5, &3): {} (equivalent to sum_positive)",
133        combined_or_false.test(&5, &3)
134    );
135    println!(
136        "  test(&-3, &-5): {} (equivalent to sum_positive)",
137        combined_or_false.test(&-3, &-5)
138    );
139
140    println!("\n=== Practical scenarios: Default pass/reject filters ===\n");
141
142    // Scenario 1: Default pass-all filter
143    let pairs = vec![(1, 2), (3, 4), (5, 6)];
144    let pass_all = BoxBiPredicate::<i32, i32>::always_true();
145    let closure = pass_all.into_fn();
146    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
147    println!("Default pass all elements: {:?} -> {:?}", pairs, filtered);
148
149    // Scenario 2: Default reject-all filter
150    let pairs = vec![(1, 2), (3, 4), (5, 6)];
151    let reject_all = BoxBiPredicate::<i32, i32>::always_false();
152    let closure = reject_all.into_fn();
153    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
154    println!("Default reject all elements: {:?} -> {:?}", pairs, filtered);
155
156    // Scenario 3: Configurable filter
157    fn configurable_filter(enable_filter: bool) -> BoxBiPredicate<i32, i32> {
158        if enable_filter {
159            BoxBiPredicate::new(|x: &i32, y: &i32| x + y > 5)
160        } else {
161            BoxBiPredicate::always_true()
162        }
163    }
164
165    let pairs = vec![(1, 2), (3, 4), (5, 6)];
166
167    let filter_enabled = configurable_filter(true);
168    let closure = filter_enabled.into_fn();
169    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
170    println!("\nFilter enabled: {:?} -> {:?}", pairs, filtered);
171
172    let filter_disabled = configurable_filter(false);
173    let closure = filter_disabled.into_fn();
174    let filtered: Vec<_> = pairs.iter().filter(|(x, y)| closure(x, y)).collect();
175    println!("Filter disabled: {:?} -> {:?}", pairs, filtered);
176}
Source

pub fn not(self) -> BoxBiPredicate<T, U>
where T: 'static, U: 'static,

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 BoxBiPredicate representing the logical negation.

Source

pub fn nand<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static, T: 'static, 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. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implements Clone). Can be:
    • A closure: |x: &T, y: &U| -> bool
    • A function pointer: fn(&T, &U) -> bool
    • Another BoxBiPredicate<T, U>
    • An RcBiPredicate<T, U>
    • An ArcBiPredicate<T, U>
    • Any type implementing BiPredicate<T, U>
§Returns

A new BoxBiPredicate representing the logical NAND.

Source

pub fn xor<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static, T: 'static, 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. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implements Clone). Can be:
    • A closure: |x: &T, y: &U| -> bool
    • A function pointer: fn(&T, &U) -> bool
    • Another BoxBiPredicate<T, U>
    • An RcBiPredicate<T, U>
    • An ArcBiPredicate<T, U>
    • Any type implementing BiPredicate<T, U>
§Returns

A new BoxBiPredicate representing the logical XOR.

Source

pub fn nor<P>(self, other: P) -> BoxBiPredicate<T, U>
where P: BiPredicate<T, U> + 'static, T: 'static, U: 'static,

Returns a bi-predicate that represents the logical NOR (NOT OR) of this bi-predicate and another.

NOR returns true only if 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. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original bi-predicate, clone it first (if it implements Clone). Can be:
    • A closure: |x: &T, y: &U| -> bool
    • A function pointer: fn(&T, &U) -> bool
    • Another BoxBiPredicate<T, U>
    • An RcBiPredicate<T, U>
    • An ArcBiPredicate<T, U>
    • Any type implementing BiPredicate<T, U>
§Returns

A new BoxBiPredicate representing the logical NOR.

Trait Implementations§

Source§

impl<T, U> BiPredicate<T, U> for BoxBiPredicate<T, U>

Source§

fn test(&self, first: &T, second: &U) -> bool

Tests whether the given values satisfy this bi-predicate. Read more
Source§

fn into_box(self) -> BoxBiPredicate<T, U>
where T: 'static, U: 'static,

Converts this bi-predicate into a BoxBiPredicate. Read more
Source§

fn into_rc(self) -> RcBiPredicate<T, U>
where T: 'static, U: 'static,

Converts this bi-predicate into an RcBiPredicate. Read more
Source§

fn into_fn(self) -> impl Fn(&T, &U) -> bool
where Self: Sized + 'static, T: 'static, U: 'static,

Converts this bi-predicate into a closure that can be used directly with standard library methods. Read more
Source§

fn into_arc(self) -> ArcBiPredicate<T, U>
where Self: Sized + Send + Sync + 'static, T: Send + Sync + 'static, U: Send + Sync + 'static,

Converts this bi-predicate into an ArcBiPredicate. Read more
Source§

impl<T, U> Debug for BoxBiPredicate<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U> Display for BoxBiPredicate<T, U>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for BoxBiPredicate<T, U>

§

impl<T, U> !RefUnwindSafe for BoxBiPredicate<T, U>

§

impl<T, U> !Send for BoxBiPredicate<T, U>

§

impl<T, U> !Sync for BoxBiPredicate<T, U>

§

impl<T, U> Unpin for BoxBiPredicate<T, U>

§

impl<T, U> !UnwindSafe for BoxBiPredicate<T, U>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.