Skip to main content

qubit_function/functions/bi_mutating_function/
arc_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 `ArcConditionalBiMutatingFunction` public type.
12
13#![allow(unused_imports)]
14
15use super::*;
16
17// ============================================================================
18// ArcConditionalBiMutatingFunction - Arc-based Conditional BiMutatingFunction
19// ============================================================================
20
21/// ArcConditionalBiMutatingFunction struct
22///
23/// A thread-safe conditional bi-mutating-function that only executes when a
24/// bi-predicate is satisfied. Uses `ArcBiMutatingFunction` and `ArcBiPredicate` for
25/// shared ownership across threads.
26///
27/// This type is typically created by calling `ArcBiMutatingFunction::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 `Arc`, multiple owners allowed
33/// - **Thread-Safe**: Implements `Send + Sync`, safe for concurrent use
34/// - **Conditional Execution**: Only computes when bi-predicate returns `true`
35/// - **Chainable**: Can add `or_else` branch to create if-then-else logic
36///
37pub struct ArcConditionalBiMutatingFunction<T, U, R> {
38    pub(super) function: ArcBiMutatingFunction<T, U, R>,
39    pub(super) predicate: ArcBiPredicate<T, U>,
40}
41
42// Implement ArcConditionalBiMutatingFunction
43impl_shared_conditional_function!(
44    ArcConditionalBiMutatingFunction<T, U, R>,
45    ArcBiMutatingFunction,
46    BiMutatingFunction,
47    into_arc,
48    Send + Sync + 'static
49);
50
51// Use macro to generate Debug and Display implementations
52impl_conditional_function_debug_display!(ArcConditionalBiMutatingFunction<T, U, R>);
53
54// Generate Clone implementation
55impl_conditional_function_clone!(ArcConditionalBiMutatingFunction<T, U, R>);