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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
use crate::;
/// Helper trait used by [`WithAbi`] (use it instead).
/// This trait is required to allow [`FnPtr`] to be a subtrait of [`WithAbi`], which eliminates
/// the need for a type bound when using a fixed abi marker.
/// Using [`WithAbi`] directly would result in a cyclic supertrait error.
/// Helper trait to change the abi of a function pointer type while preserving its safety, arguments and return type.
///
/// This is used by [`with_abi!`](crate::with_abi) under the hood.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::{abi, WithAbi};
/// type F = extern "C" fn(i32) -> i32;
/// type G = <F as WithAbi<abi::System>>::F;
/// // `G` is `extern "system" fn(i32) -> i32`
/// # static_assertions::assert_type_eq_all!(G, extern "system" fn(i32) -> i32);
/// ```
/// Helper trait used by [`WithSafety`] (use it instead).
/// This trait is required to allow [`FnPtr`] to be a subtrait of [`WithSafety`], which eliminates
/// the need for a type bound when using a fixed safety marker.
/// Using [`WithSafety`] directly would result in a cyclic supertrait error.
/// Helper trait to change the safety of a function pointer type while preserving its abi, arguments and return type.
///
/// This is used by [`with_safety!`](crate::with_safety) under the hood.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::{WithSafety, safety};
/// type F = extern "C" fn(i32) -> i32;
/// type G = <F as WithSafety<safety::Unsafe>>::F;
/// // `G` is `unsafe extern "C" fn(i32) -> i32`
/// # static_assertions::assert_type_eq_all!(G, unsafe extern "C" fn(i32) -> i32);
/// ```
/// Helper trait to compute the safe version of a function pointer type while preserving its abi, arguments and return type. Equivalent to [`WithSafety<Safe>`].
///
/// # Example
///
/// ```rust
/// # use fn_ptr::AsSafe;
/// type U = unsafe extern "C" fn(i32) -> i32;
/// type S = <U as AsSafe>::F;
/// // `S` is `extern "C" fn(i32) -> i32`
/// # static_assertions::assert_type_eq_all!(S, extern "C" fn(i32) -> i32);
/// ```
/// Helper trait to compute the unsafe version of a function pointer type while preserving arity, abi and signature.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::AsUnsafe;
/// type S = extern "C" fn(i32) -> i32;
/// type U = <S as AsUnsafe<S>>::F;
/// // `U` is `unsafe extern "C" fn(i32) -> i32`
/// # static_assertions::assert_type_eq_all!(U, unsafe extern "C" fn(i32) -> i32);
/// ```
/// Helper trait used by [`WithOutput`] (use it instead).
/// This trait is required to allow [`FnPtr`] to be a subtrait of [`WithOutput`], which eliminates
/// the need for a type bound when using a fixed output type.
/// Using [`WithOutput`] directly would result in a cyclic supertrait error.
/// Helper trait to change the return type of a function pointer type while preserving its safety, abi and arguments.
///
/// This is used by [`with_output!`](crate::with_output) under the hood.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::WithOutput;
/// type F = extern "C" fn(i32) -> i32;
/// type G = <F as WithOutput<u32>>::F;
/// // `G` is `extern "C" fn(i32) -> u32`
/// # static_assertions::assert_type_eq_all!(G, extern "C" fn(i32) -> u32);
/// ```
/// Helper trait used by [`WithArgs`] (use it instead).
/// This trait is required to allow [`FnPtr`] to be a subtrait of [`WithArgs`], which eliminates
/// the need for a type bound when using a fixed args type.
/// Using [`WithArgs`] directly would result in a cyclic supertrait error.
/// Helper trait to change the argument types of a function pointer type while preserving its safety, abi and return type.
///
/// This is used by [`with_args!`](crate::with_args) under the hood.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::WithArgs;
/// type F = extern "C" fn(i32) -> i32;
/// type G = <F as WithArgs<(u8, u16)>>::F;
/// // `G` `extern "C" fn(u8, u16) -> i32`
/// # static_assertions::assert_type_eq_all!(G, extern "C" fn(u8, u16) -> i32);
/// ```
/// Construct a function-pointer type identical to the given one but using the specified abi.
///
/// Accepts either:
/// - an [`Abi`](crate::abi::Abi) marker type (e.g. [`C`](crate::abi::C), [`SysV64`](crate::abi::SysV64))
/// - a string literal (e.g. `"C"`, `"system"`, `"stdcall"`).
///
/// # Examples
///
/// ```rust
/// # use fn_ptr::{with_abi, abi};
/// type F = with_abi!(abi::Rust, extern "C" fn(i32) -> i32);
/// // `F` is `fn(i32) -> i32` (equivalent to `extern "Rust" fn(i32) -> i32`)
/// # static_assertions::assert_type_eq_all!(F, fn(i32) -> i32);
///
/// type G = with_abi!("C", extern "system" fn());
/// // `G` is `extern "C" fn()`
/// # static_assertions::assert_type_eq_all!(G, extern "C" fn());
/// ```
/// Construct a function-pointer type identical to the given one but using
/// the specified safety.
///
/// Accepts either:
/// - a [`Safety`](crate::safety::Safety) marker type ([`Safe`](crate::safety::Safe) or [`Unsafe`](crate::safety::Unsafe))
/// - safety keyword (`safe` or `unsafe`).
/// - a boolean literal.
///
/// # Examples
///
/// ```rust
/// # use fn_ptr::{with_safety, safety};
/// type F = with_safety!(safety::Safe, unsafe extern "C" fn(i32) -> i32);
/// // `F` is `extern "C" fn(i32) -> i32`
/// # static_assertions::assert_type_eq_all!(F, extern "C" fn(i32) -> i32);
///
/// type G = with_safety!(unsafe, fn());
/// // `G` is `unsafe fn()`
/// # static_assertions::assert_type_eq_all!(G, unsafe fn());
/// ```
/// Construct a function-pointer type identical to the given one but `safe`.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::make_safe;
/// type U = unsafe extern "C" fn(i32);
/// type S = make_safe!(U);
/// // `S` is `extern "C" fn(i32)`
/// # static_assertions::assert_type_eq_all!(S, extern "C" fn(i32));
/// ```
/// Construct a function-pointer type identical to the given one but `unsafe`.
///
/// # Example
///
/// ```rust
/// # use fn_ptr::make_unsafe;
/// type S = extern "C" fn(i32);
/// type U = make_unsafe!(S);
/// // `U` is `unsafe extern "C" fn(i32)`
/// # static_assertions::assert_type_eq_all!(U, unsafe extern "C" fn(i32));
/// ```
/// Construct a function-pointer type identical to the given one but using
/// the specified return type.
///
/// # Examples
///
/// ```rust
/// # use fn_ptr::with_output;
/// type F = extern "C" fn(i32) -> i32;
/// type G = with_output!(u64, F);
/// // `G` is `extern "C" fn(i32) -> u64`
/// # static_assertions::assert_type_eq_all!(G, extern "C" fn(i32) -> u64);
/// ```
/// Construct a function-pointer type identical to the given one but using
/// the specified argument tuple type.
///
/// # Examples
///
/// ```rust
/// # use fn_ptr::with_args;
/// type F = extern "C" fn(i32) -> i32;
/// type G = with_args!((u8, u16), F);
/// // `G` is `extern "C" fn(u8, u16) -> i32`
/// # static_assertions::assert_type_eq_all!(G, extern "C" fn(u8, u16) -> i32);
/// ```