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