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
/*******************************************************************************
*
* 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
//!
//! ```text
//! impl_function_identity!(BoxFunction<T>);
//! impl_function_identity!(RcFunction<T>);
//! impl_function_identity!(ArcFunction<T>);
//! impl_function_identity!(BoxBiFunction<T, U>);
//! impl_function_identity!(ArcBiFunction<T, U>);
//! ```
//!
//! # Generated Implementation
//!
//! For single-parameter functions, the macro generates:
//!
//! ```text
//! impl<T> BoxFunction<T, T> where T: Clone {
//! pub fn identity() -> BoxFunction<T, T>;
//! }
//! ```
//!
//! For two-parameter functions, the macro generates:
//!
//! ```text
//! impl<T, U> ArcBiFunction<T, U, T> where T: Clone {
//! pub fn identity() -> ArcBiFunction<T, U, T>;
//! }
//! ```
//!
//! # 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
///
/// ```text
/// 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;