pub struct ArcConditionalStatefulFunction<T, R> { /* private fields */ }Expand description
ArcConditionalStatefulFunction struct
A thread-safe conditional function that only executes when a predicate
is satisfied. Uses ArcStatefulFunction and ArcPredicate for shared
ownership across threads.
This type is typically created by calling ArcStatefulFunction::when() and is
designed to work with the or_else() method to create if-then-else
logic.
§Features
- Shared Ownership: Cloneable via
Arc, multiple owners allowed - Thread-Safe: Implements
Send, safe for concurrent use - Conditional Execution: Only maps when predicate returns
true - Chainable: Can add
or_elsebranch to create if-then-else logic
§Examples
use qubit_function::{StatefulFunction, ArcStatefulFunction};
let mut function = ArcStatefulFunction::new(|x: &i32| x * 2)
.when(|x: &i32| *x > 0)
.or_else(|x: &i32| -x);
let mut function_clone = function.clone();
assert_eq!(function.apply(&5), 10);
assert_eq!(function_clone.apply(&-5), 5);§Author
Haixing Hu
Implementations§
Source§impl<T, R> ArcConditionalStatefulFunction<T, R>
impl<T, R> ArcConditionalStatefulFunction<T, R>
Sourcepub fn or_else<F>(&self, else_function: F) -> ArcStatefulFunction<T, R>
pub fn or_else<F>(&self, else_function: F) -> ArcStatefulFunction<T, R>
Provides an alternative function for when the predicate is not satisfied
Combines the current conditional function with an alternative function into a new function that implements the following semantics:
When the returned function is called with an argument:
- If the predicate is satisfied, it executes the internal function
- If the predicate is NOT satisfied, it executes the alternative function
§Parameters
else_function- The alternative function to execute when predicate fails
§Returns
Returns a new function that handles both conditional branches
§Examples
// Macro internals are crate-private; usage example is documented at
// the macro expansion site.Trait Implementations§
Source§impl<T, R> Clone for ArcConditionalStatefulFunction<T, R>
impl<T, R> Clone for ArcConditionalStatefulFunction<T, R>
Source§impl<T, R> Debug for ArcConditionalStatefulFunction<T, R>
impl<T, R> Debug for ArcConditionalStatefulFunction<T, R>
Auto Trait Implementations§
impl<T, R> Freeze for ArcConditionalStatefulFunction<T, R>
impl<T, R> !RefUnwindSafe for ArcConditionalStatefulFunction<T, R>
impl<T, R> Send for ArcConditionalStatefulFunction<T, R>
impl<T, R> Sync for ArcConditionalStatefulFunction<T, R>
impl<T, R> Unpin for ArcConditionalStatefulFunction<T, R>
impl<T, R> UnsafeUnpin for ArcConditionalStatefulFunction<T, R>
impl<T, R> !UnwindSafe for ArcConditionalStatefulFunction<T, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more