FnTesterOps

Trait FnTesterOps 

Source
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§

Source

fn and<T>(self, other: T) -> BoxTester
where 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 implements Clone). Can be:
    • Another closure
    • A function pointer
    • A BoxTester, RcTester, or ArcTester
§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());
Source

fn or<T>(self, other: T) -> BoxTester
where 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 implements Clone). Can be:
    • Another closure
    • A function pointer
    • A BoxTester, RcTester, or ArcTester
    • 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());
Source

fn not(self) -> BoxTester

Returns a tester that represents the logical negation of this tester

§Return Value

A BoxTester representing the logical negation

§Examples
use prism3_function::{FnTesterOps, Tester};

let is_ready = || false;
let not_ready = is_ready.not();
assert!(not_ready.test());
Source

fn nand<T>(self, other: T) -> BoxTester
where 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 implements Clone). Accepts closures, function pointers, or any Tester implementation.
§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) = false
Source

fn xor<T>(self, other: T) -> BoxTester
where 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 implements Clone). Accepts closures, function pointers, or any Tester implementation.
§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 = true
Source

fn nor<T>(self, other: T) -> BoxTester
where 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 implements Clone). Accepts closures, function pointers, or any Tester implementation.
§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) = true

Dyn 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.

Implementors§

Source§

impl<F> FnTesterOps for F
where F: Fn() -> bool + 'static,