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
13use super::{
14 BiMutatingFunction,
15 BiPredicate,
16 RcBiMutatingFunction,
17 RcBiPredicate,
18 impl_conditional_function_clone,
19 impl_conditional_function_debug_display,
20 impl_shared_conditional_function,
21};
22
23// ============================================================================
24// RcConditionalBiMutatingFunction - Rc-based Conditional BiMutatingFunction
25// ============================================================================
26
27/// RcConditionalBiMutatingFunction struct
28///
29/// A single-threaded conditional bi-mutating-function that only executes when a
30/// bi-predicate is satisfied. Uses `RcBiMutatingFunction` and `RcBiPredicate` for
31/// shared ownership within a single thread.
32///
33/// This type is typically created by calling `RcBiMutatingFunction::when()` and is
34/// designed to work with the `or_else()` method to create if-then-else logic.
35///
36/// # Features
37///
38/// - **Shared Ownership**: Cloneable via `Rc`, multiple owners allowed
39/// - **Single-Threaded**: Not thread-safe, cannot be sent across threads
40/// - **Conditional Execution**: Only computes when bi-predicate returns `true`
41/// - **No Lock Overhead**: More efficient than `ArcConditionalBiMutatingFunction`
42///
43pub struct RcConditionalBiMutatingFunction<T, U, R> {
44 pub(super) function: RcBiMutatingFunction<T, U, R>,
45 pub(super) predicate: RcBiPredicate<T, U>,
46}
47
48// Implement RcConditionalBiMutatingFunction
49impl_shared_conditional_function!(
50 RcConditionalBiMutatingFunction<T, U, R>,
51 RcBiMutatingFunction,
52 BiMutatingFunction,
53 into_rc,
54 'static
55);
56
57// Use macro to generate Debug and Display implementations
58impl_conditional_function_debug_display!(RcConditionalBiMutatingFunction<T, U, R>);
59
60// Generate Clone implementation
61impl_conditional_function_clone!(RcConditionalBiMutatingFunction<T, U, R>);