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