1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// =============================================================================
// Copyright (c) 2025 - 2026 Haixing Hu.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0.
// =============================================================================
//! Defines the `RcConditionalBiMutatingFunction` public type.
use crateBiMutatingFunction;
use crateBiPredicate;
use crateRcBiMutatingFunction;
use crateRcBiPredicate;
use crateimpl_conditional_function_clone;
use crateimpl_conditional_function_debug_display;
use crateimpl_shared_conditional_function;
// ============================================================================
// RcConditionalBiMutatingFunction - Rc-based Conditional BiMutatingFunction
// ============================================================================
/// A shared conditional callback that may mutate two inputs.
///
/// The stored [`RcBiMutatingFunction`] runs only when the stored
/// [`RcBiPredicate`] accepts both inputs. This wrapper shares its callback and
/// predicate through `Rc`, so it is intended for use within a single thread.
///
/// Create this type with [`RcBiMutatingFunction::when`]. Use [`Self::or_else`]
/// to provide a callback for the predicate-false branch.
///
/// # Type Parameters
///
/// - `T` - Type of the first mutable input.
/// - `U` - Type of the second mutable input.
/// - `R` - Type of the callback result.
///
/// # Examples
///
/// ```
/// use qubit_function::{BiMutatingFunction, RcBiMutatingFunction};
///
/// let add_if_positive = RcBiMutatingFunction::new(
/// |first: &mut i32, second: &mut i32| {
/// *first += *second;
/// *first
/// },
/// )
/// .when(|first: &i32, second: &i32| *first > 0 && *second > 0);
/// let callback = add_if_positive.or_else(|_: &mut i32, _: &mut i32| 0);
/// let mut first = 2;
/// let mut second = 3;
///
/// assert_eq!(callback.apply(&mut first, &mut second), 5);
/// assert_eq!(first, 5);
/// assert_eq!(second, 3);
/// ```
// Implement RcConditionalBiMutatingFunction
impl_shared_conditional_function!;
// Use macro to generate Debug and Display implementations
impl_conditional_function_debug_display!;
// Generate Clone implementation
impl_conditional_function_clone!;