1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
*
* Copyright (c) 2025 - 2026.
* Haixing Hu, Qubit Co. Ltd.
*
* All rights reserved.
*
******************************************************************************/
//! # Function Identity Macro
//!
//! Generates identity method implementation for function types.
//!
//! This macro generates an `impl` block that implements the `identity()` method
//! for function types that have identical input and output types (T -> T).
//!
//! # Parameters
//!
//! * `$struct_name` - The struct name (e.g., `BoxFunction`, `RcFunction`, `ArcFunction`)
//! * `$t:ident` - The generic type parameter name (usually `T`)
//!
//! # Usage
//!
//! ```ignore
//! impl_function_identity!(BoxFunction<T>);
//! impl_function_identity!(RcFunction<T>);
//! impl_function_identity!(ArcFunction<T>);
//! impl_function_identity!(BoxBiFunction<T, U>);
//! ```
//!
//! # Generated Implementation
//!
//! For single-parameter functions, the macro generates:
//!
//! ```ignore
//! impl<T> $struct_name<T, T>
//! where
//! T: Clone,
//! {
//! /// Creates an identity function
//! ///
//! /// # Examples
//! ///
//! /// ```rust
//! /// use qubit_function::{$struct_name, Function};
//! ///
//! /// let identity = $struct_name::<i32, i32>::identity();
//! /// assert_eq!(identity.apply(&42), 42);
//! /// ```
//! pub fn identity() -> $struct_name<T, T> {
//! $struct_name::new(|x: &T| x.clone())
//! }
//! }
//! ```
//!
//! For two-parameter functions, the macro generates:
//!
//! ```ignore
//! impl<T, U> $struct_name<T, U, T>
//! where
//! T: Clone,
//! {
//! /// Creates an identity function
//! ///
//! /// # Examples
//! ///
//! /// ```rust
//! /// use qubit_function::{$struct_name, BiFunction};
//! ///
//! /// let identity = $struct_name::<i32, String, i32>::identity();
//! /// assert_eq!(identity.apply(&42, &"test".to_string()), 42);
//! /// ```
//! pub fn identity() -> $struct_name<T, U, T> {
//! $struct_name::new(|x: &T, _: &U| x.clone())
//! }
//! }
//! ```
//!
//! # Author
//!
//! Haixing Hu
/// Generates identity method implementation for function types.
///
/// This macro generates an `impl` block that implements the `identity()` method
/// for function types that have identical input and output types (T -> T).
///
/// # Parameters
///
/// * `$struct_name<$input_type, $output_type>` - The struct name with two generic type parameters
/// - Both generic parameters must be the same type identifier (e.g., `BoxFunction<T, T>`)
/// - Note: The macro caller must ensure $input_type and $output_type are identical
///
/// # Usage
///
/// ```rust,ignore
/// impl_function_identity_method!(BoxFunction<T, T>);
/// impl_function_identity_method!(RcFunction<T, T>);
/// impl_function_identity_method!(ArcFunction<T, T>);
/// impl_function_identity_method!(BoxFunctionOnce<T, T>);
/// impl_function_identity_method!(BoxMutatingFunction<T, T>);
/// impl_function_identity_method!(BoxStatefulFunction<T, T>);
/// ```
///
/// # Author
///
/// Haixing Hu
pub use impl_function_identity_method;