Skip to main content

qubit_function/functions/bi_mutating_function/
rc_conditional_bi_mutating_function.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 *    SPDX-License-Identifier: Apache-2.0
6 *
7 *    Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10// qubit-style: allow explicit-imports
11//! Defines the `RcConditionalBiMutatingFunction` public type.
12
13#![allow(unused_imports)]
14
15use super::*;
16
17// ============================================================================
18// RcConditionalBiMutatingFunction - Rc-based Conditional BiMutatingFunction
19// ============================================================================
20
21/// RcConditionalBiMutatingFunction struct
22///
23/// A single-threaded conditional bi-mutating-function that only executes when a
24/// bi-predicate is satisfied. Uses `RcBiMutatingFunction` and `RcBiPredicate` for
25/// shared ownership within a single thread.
26///
27/// This type is typically created by calling `RcBiMutatingFunction::when()` and is
28/// designed to work with the `or_else()` method to create if-then-else logic.
29///
30/// # Features
31///
32/// - **Shared Ownership**: Cloneable via `Rc`, multiple owners allowed
33/// - **Single-Threaded**: Not thread-safe, cannot be sent across threads
34/// - **Conditional Execution**: Only computes when bi-predicate returns `true`
35/// - **No Lock Overhead**: More efficient than `ArcConditionalBiMutatingFunction`
36///
37pub struct RcConditionalBiMutatingFunction<T, U, R> {
38    pub(super) function: RcBiMutatingFunction<T, U, R>,
39    pub(super) predicate: RcBiPredicate<T, U>,
40}
41
42// Implement RcConditionalBiMutatingFunction
43impl_shared_conditional_function!(
44    RcConditionalBiMutatingFunction<T, U, R>,
45    RcBiMutatingFunction,
46    BiMutatingFunction,
47    into_rc,
48    'static
49);
50
51// Use macro to generate Debug and Display implementations
52impl_conditional_function_debug_display!(RcConditionalBiMutatingFunction<T, U, R>);
53
54// Generate Clone implementation
55impl_conditional_function_clone!(RcConditionalBiMutatingFunction<T, U, R>);