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
Fnwithout needingRefCell - 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
impl RcTester
Sourcepub fn and(&self, next: &RcTester) -> RcTester
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 availableSourcepub fn or(&self, next: &RcTester) -> RcTester
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 availableSourcepub fn not(&self) -> RcTester
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 availableSourcepub fn nand(&self, next: &RcTester) -> RcTester
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());Sourcepub fn xor(&self, next: &RcTester) -> RcTester
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());Sourcepub fn nor(&self, next: &RcTester) -> RcTester
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());