Skip to main content

qubit_function/functions/bi_mutating_function/
box_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 `BoxConditionalBiMutatingFunction` public type.
12
13use super::{
14    BiMutatingFunction,
15    BiPredicate,
16    BoxBiMutatingFunction,
17    BoxBiPredicate,
18    impl_box_conditional_function,
19    impl_conditional_function_debug_display,
20};
21
22// ============================================================================
23// BoxConditionalBiMutatingFunction - Box-based Conditional BiMutatingFunction
24// ============================================================================
25
26/// BoxConditionalBiMutatingFunction struct
27///
28/// A conditional bi-mutating-function that only executes when a bi-predicate is
29/// satisfied. Uses `BoxBiMutatingFunction` and `BoxBiPredicate` for single
30/// ownership semantics.
31///
32/// This type is typically created by calling `BoxBiMutatingFunction::when()` and is
33/// designed to work with the `or_else()` method to create if-then-else logic.
34///
35/// # Features
36///
37/// - **Single Ownership**: Not cloneable, ownership moves on use
38/// - **Conditional Execution**: Only computes when bi-predicate returns `true`
39/// - **Chainable**: Can add `or_else` branch to create if-then-else logic
40/// - **Implements BiMutatingFunction**: Can be used anywhere a `BiMutatingFunction` is expected
41///
42pub struct BoxConditionalBiMutatingFunction<T, U, R> {
43    pub(super) function: BoxBiMutatingFunction<T, U, R>,
44    pub(super) predicate: BoxBiPredicate<T, U>,
45}
46
47// Implement BoxConditionalBiMutatingFunction
48impl_box_conditional_function!(
49    BoxConditionalBiMutatingFunction<T, U, R>,
50    BoxBiMutatingFunction,
51    BiMutatingFunction
52);
53
54// Use macro to generate Debug and Display implementations
55impl_conditional_function_debug_display!(BoxConditionalBiMutatingFunction<T, U, R>);