pub trait FnTesterOps:
Sized
+ Fn() -> bool
+ 'static {
// Provided methods
fn and<T>(self, other: T) -> BoxTester
where T: Tester + 'static { ... }
fn or<T>(self, other: T) -> BoxTester
where T: Tester + 'static { ... }
fn not(self) -> BoxTester { ... }
fn nand<T>(self, other: T) -> BoxTester
where T: Tester + 'static { ... }
fn xor<T>(self, other: T) -> BoxTester
where T: Tester + 'static { ... }
fn nor<T>(self, other: T) -> BoxTester
where T: Tester + 'static { ... }
}Expand description
Extension trait providing logical composition methods for closures
This trait is automatically implemented for all closures and function
pointers that match Fn() -> bool, enabling method chaining starting
from a closure.
§Examples
use prism3_function::{FnTesterOps, Tester};
let is_ready = || true;
let is_available = || true;
// Combine testers using extension methods
let combined = is_ready.and(is_available);
assert!(combined.test());§Author
Hu Haixing
Provided Methods§
Sourcefn and<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
fn and<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
Returns a tester that represents the logical AND of this tester and another
§Parameters
other- The other tester to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original tester, clone it first (if it implementsClone). Can be:- Another closure
- A function pointer
- A
BoxTester,RcTester, orArcTester
§Return Value
A BoxTester representing the logical AND
§Examples
use prism3_function::{FnTesterOps, Tester};
let is_ready = || true;
let is_available = || true;
let combined = is_ready.and(is_available);
assert!(combined.test());Sourcefn or<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
fn or<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
Returns a tester that represents the logical OR of this tester and another
§Parameters
other- The other tester to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original tester, clone it first (if it implementsClone). Can be:- Another closure
- A function pointer
- A
BoxTester,RcTester, orArcTester - Any type implementing
Tester
§Return Value
A BoxTester representing the logical OR
§Examples
use prism3_function::{FnTesterOps, Tester};
let is_ready = || false;
let is_fallback = || true;
let combined = is_ready.or(is_fallback);
assert!(combined.test());Sourcefn nand<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
fn nand<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
Returns a tester that represents the logical NAND (NOT AND) of this tester and another
NAND returns true unless both testers are true.
Equivalent to !(self AND other).
§Parameters
other- The other tester to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original tester, clone it first (if it implementsClone). Accepts closures, function pointers, or anyTesterimplementation.
§Return Value
A BoxTester representing the logical NAND
§Examples
use prism3_function::{FnTesterOps, Tester};
let is_ready = || true;
let is_available = || true;
let nand = is_ready.nand(is_available);
assert!(!nand.test()); // !(true && true) = falseSourcefn xor<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
fn xor<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
Returns a tester that represents the logical XOR (exclusive OR) of this tester and another
XOR returns true if exactly one of the testers is true.
§Parameters
other- The other tester to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original tester, clone it first (if it implementsClone). Accepts closures, function pointers, or anyTesterimplementation.
§Return Value
A BoxTester representing the logical XOR
§Examples
use prism3_function::{FnTesterOps, Tester};
let is_ready = || true;
let is_available = || false;
let xor = is_ready.xor(is_available);
assert!(xor.test()); // true ^ false = trueSourcefn nor<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
fn nor<T>(self, other: T) -> BoxTesterwhere
T: Tester + 'static,
Returns a tester that represents the logical NOR (NOT OR) of this tester and another
NOR returns true only when both testers are false. Equivalent
to !(self OR other).
§Parameters
other- The other tester to combine with. Note: This parameter is passed by value and will transfer ownership. If you need to preserve the original tester, clone it first (if it implementsClone). Accepts closures, function pointers, or anyTesterimplementation.
§Return Value
A BoxTester representing the logical NOR
§Examples
use prism3_function::{FnTesterOps, Tester};
let is_ready = || false;
let is_available = || false;
let nor = is_ready.nor(is_available);
assert!(nor.test()); // !(false || false) = trueDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.