pub struct BoxConditionalBiMutatingFunction<T, U, R> { /* private fields */ }Expand description
BoxConditionalBiMutatingFunction struct
A conditional bi-mutating-function that only executes when a bi-predicate is
satisfied. Uses BoxBiMutatingFunction and BoxBiPredicate for single
ownership semantics.
This type is typically created by calling BoxBiMutatingFunction::when() and is
designed to work with the or_else() method to create if-then-else logic.
§Features
- Single Ownership: Not cloneable, ownership moves on use
- Conditional Execution: Only computes when bi-predicate returns
true - Chainable: Can add
or_elsebranch to create if-then-else logic - Implements BiMutatingFunction: Can be used anywhere a
BiMutatingFunctionis expected
§Author
Haixing Hu
Implementations§
Source§impl<T, U, R> BoxConditionalBiMutatingFunction<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
impl<T, U, R> BoxConditionalBiMutatingFunction<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
Sourcepub fn or_else<F>(self, else_function: F) -> BoxBiMutatingFunction<T, U, R>where
F: BiMutatingFunction<T, U, R> + 'static,
pub fn or_else<F>(self, else_function: F) -> BoxBiMutatingFunction<T, U, R>where
F: BiMutatingFunction<T, U, R> + 'static,
Provides an alternative function for when the predicate is not satisfied
Combines the current conditional bifunction with an alternative bifunction into a new bifunction that implements the following semantics:
When the returned bifunction is called with two arguments:
- If the predicate is satisfied, it executes the internal bifunction
- If the predicate is NOT satisfied, it executes the alternative bifunction
§Parameters
else_function- The alternative bifunction to execute when predicate fails
§Returns
Returns a new bifunction that handles both conditional branches
§Examples
ⓘ
let func = BoxBiFunction::new(|x: i32, y: i32| x + y);
let alternative = BoxBiFunction::new(|x: i32, y: i32| x * y);
let conditional = func.when(|x, y| *x > 0 && *y > 0).or_else(alternative);
assert_eq!(conditional.apply(3, 4), 7); // 3 + 4 = 7 (predicate satisfied)
assert_eq!(conditional.apply(-2, 4), -8); // -2 * 4 = -8 (predicate failed)Trait Implementations§
Source§impl<T, U, R> Debug for BoxConditionalBiMutatingFunction<T, U, R>
impl<T, U, R> Debug for BoxConditionalBiMutatingFunction<T, U, R>
Auto Trait Implementations§
impl<T, U, R> Freeze for BoxConditionalBiMutatingFunction<T, U, R>
impl<T, U, R> !RefUnwindSafe for BoxConditionalBiMutatingFunction<T, U, R>
impl<T, U, R> !Send for BoxConditionalBiMutatingFunction<T, U, R>
impl<T, U, R> !Sync for BoxConditionalBiMutatingFunction<T, U, R>
impl<T, U, R> Unpin for BoxConditionalBiMutatingFunction<T, U, R>
impl<T, U, R> !UnwindSafe for BoxConditionalBiMutatingFunction<T, U, 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