Tester

Trait Tester 

Source
pub trait Tester {
    // Required methods
    fn test(&self) -> bool;
    fn into_box(self) -> BoxTester
       where Self: Sized + 'static;
    fn into_rc(self) -> RcTester
       where Self: Sized + 'static;

    // Provided method
    fn into_arc(self) -> ArcTester
       where Self: Sized + Send + Sync + 'static { ... }
}
Expand description

Tests whether a state or condition holds

Tester is a functional abstraction for testing states or conditions. It accepts no parameters and returns a boolean value indicating the test result of some state or condition.

§Core Characteristics

  • No input parameters: Captures context through closures
  • Returns boolean: Indicates test results
  • Uses &self: Does not modify its own state, only reads external state
  • Repeatable calls: The same Tester can call test() multiple times

§Use Cases

  • State checking: Check system or service status
  • Condition waiting: Repeatedly check until conditions are met
  • Health monitoring: Check system health status
  • Precondition validation: Verify conditions before operations

§Design Philosophy

Tester’s responsibility is “test judgment”, not “state management”. State management is the caller’s responsibility. Tester only reads state and returns judgment results.

§Examples

use prism3_function::{BoxTester, Tester};
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};

// State managed externally
let ready = Arc::new(AtomicBool::new(false));
let ready_clone = Arc::clone(&ready);

// Tester only responsible for reading state
let tester = BoxTester::new(move || {
    ready_clone.load(Ordering::Acquire)
});

// Can be called multiple times
assert!(!tester.test());
ready.store(true, Ordering::Release);
assert!(tester.test());

§Author

Hu Haixing

Required Methods§

Source

fn test(&self) -> bool

Executes the test and returns the test result

This method can be called multiple times without modifying the Tester’s own state.

§Return Value

Returns true if the condition holds, otherwise returns false

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

let tester = BoxTester::new(|| true);
assert!(tester.test());
Source

fn into_box(self) -> BoxTester
where Self: Sized + 'static,

Converts this tester to BoxTester

§Return Value

A BoxTester that wraps this tester

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

let closure = || true;
let boxed: BoxTester = closure.into_box();
Source

fn into_rc(self) -> RcTester
where Self: Sized + 'static,

Converts this tester to RcTester

§Return Value

A RcTester that wraps this tester

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

let closure = || true;
let rc: RcTester = closure.into_rc();

Provided Methods§

Source

fn into_arc(self) -> ArcTester
where Self: Sized + Send + Sync + 'static,

Converts this tester to ArcTester

§Return Value

An ArcTester that wraps this tester

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

let closure = || true;
let arc: ArcTester = closure.into_arc();

Implementors§

Source§

impl Tester for ArcTester

Source§

impl Tester for BoxTester

Source§

impl Tester for RcTester

Source§

impl<F> Tester for F
where F: Fn() -> bool,