RcTester

Struct RcTester 

Source
pub struct RcTester { /* private fields */ }
Expand description

Single-threaded shared ownership Tester implemented using Rc

RcTester wraps a closure in Rc<dyn Fn() -> bool>, allowing the tester to be cloned and shared within a single thread. Since it doesn’t use atomic operations, it has lower overhead than ArcTester.

§Characteristics

  • Shared ownership: Can be cloned
  • Single-threaded: Cannot be sent across threads
  • Low overhead: Uses Fn without needing RefCell
  • Borrowing combination: and()/or()/not() borrow &self

§Use Cases

  • Single-threaded testing scenarios requiring sharing
  • Event-driven systems (single-threaded)
  • Callback-intensive code requiring cloneable tests
  • Performance-sensitive single-threaded code

§Examples

use prism3_function::{RcTester, Tester};

let shared = RcTester::new(|| true);

// Clone for multiple uses
let clone1 = shared.clone();
let clone2 = shared.clone();

// Non-consuming combination
let combined = shared.and(&clone1);

§Author

Hu Haixing

Implementations§

Source§

impl RcTester

Source

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

Creates a new RcTester from a closure

§Type Parameters
  • F - Closure type implementing Fn() -> bool
§Parameters
  • f - The closure to wrap
§Return Value

A new RcTester instance

§Examples
use prism3_function::RcTester;

let tester = RcTester::new(|| true);
Source

pub fn and(&self, next: &RcTester) -> RcTester

Combines this tester with another tester using logical AND

Returns a new RcTester that returns true only when both tests pass. Borrows &self, so the original tester remains available.

§Parameters
  • next - The tester to combine with
§Return Value

A new RcTester representing logical AND

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

let first = RcTester::new(|| true);
let second = RcTester::new(|| true);
let combined = first.and(&second);
// first and second are still available
Source

pub fn or(&self, next: &RcTester) -> RcTester

Combines this tester with another tester using logical OR

Returns a new RcTester that returns true if either test passes. Borrows &self, so the original tester remains available.

§Parameters
  • next - The tester to combine with
§Return Value

A new RcTester representing logical OR

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

let first = RcTester::new(|| false);
let second = RcTester::new(|| true);
let combined = first.or(&second);
// first and second are still available
Source

pub fn not(&self) -> RcTester

Negates the result of this tester

Returns a new RcTester that returns the opposite value of the original test result. Borrows &self, so the original tester remains available.

§Return Value

A new RcTester representing logical NOT

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

let original = RcTester::new(|| true);
let negated = original.not();
// original is still available
Source

pub fn nand(&self, next: &RcTester) -> RcTester

Combines this tester with another tester using logical NAND

Returns a new RcTester that returns true unless both tests pass. Borrows &self, so the original tester remains available.

§Parameters
  • next - The tester to combine with
§Return Value

A new RcTester representing logical NAND

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

let first = RcTester::new(|| true);
let second = RcTester::new(|| true);
let nand = first.nand(&second);

// Both true returns false
assert!(!nand.test());

// first and second still available
assert!(first.test());
assert!(second.test());
Source

pub fn xor(&self, next: &RcTester) -> RcTester

Combines this tester with another tester using logical XOR

Returns a new RcTester that returns true if exactly one test passes. Borrows &self, so the original tester remains available.

§Parameters
  • next - The tester to combine with
§Return Value

A new RcTester representing logical XOR

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

let first = RcTester::new(|| true);
let second = RcTester::new(|| false);
let xor = first.xor(&second);

// One true one false returns true
assert!(xor.test());

// first and second still available
assert!(first.test());
assert!(!second.test());
Source

pub fn nor(&self, next: &RcTester) -> RcTester

Combines this tester with another tester using logical NOR

Returns a new RcTester that returns true only when both tests fail. Borrows &self, so the original tester remains available.

§Parameters
  • next - The tester to combine with
§Return Value

A new RcTester representing logical NOR

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

let first = RcTester::new(|| false);
let second = RcTester::new(|| false);
let nor = first.nor(&second);

// Both false returns true
assert!(nor.test());

// first and second still available
assert!(!first.test());
assert!(!second.test());

Trait Implementations§

Source§

impl Clone for RcTester

Source§

fn clone(&self) -> Self

Creates a clone of this RcTester.

The cloned instance shares the same underlying function with the original, allowing multiple references to the same test logic.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Tester for RcTester

Source§

fn test(&self) -> bool

Executes the test and returns the test result Read more
Source§

fn into_box(self) -> BoxTester

Converts this tester to BoxTester Read more
Source§

fn into_rc(self) -> RcTester

Converts this tester to RcTester Read more
Source§

fn into_fn(self) -> impl Fn() -> bool

Converts this tester to a boxed function pointer Read more
Source§

fn to_box(&self) -> BoxTester

Clones and converts this tester to BoxTester Read more
Source§

fn to_rc(&self) -> RcTester

Clones and converts this tester to RcTester Read more
Source§

fn to_fn(&self) -> impl Fn() -> bool

Clones and converts this tester to a boxed function pointer Read more
Source§

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

Converts this tester to ArcTester Read more
Source§

fn to_arc(&self) -> ArcTester
where Self: Clone + Send + Sync + 'static,

Clones and converts this tester to ArcTester Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.