1 | #![allow (unused_macros)] |
2 | |
3 | macro_rules! feature { |
4 | ( |
5 | #![$meta:meta] |
6 | $($item:item)* |
7 | ) => { |
8 | $( |
9 | #[cfg($meta)] |
10 | #[cfg_attr(docsrs, doc(cfg($meta)))] |
11 | $item |
12 | )* |
13 | } |
14 | } |
15 | |
16 | /// Enables Windows-specific code. |
17 | /// Use this macro instead of `cfg(windows)` to generate docs properly. |
18 | macro_rules! cfg_windows { |
19 | ($($item:item)*) => { |
20 | $( |
21 | #[cfg(any(all(doc, docsrs), windows))] |
22 | #[cfg_attr(docsrs, doc(cfg(windows)))] |
23 | $item |
24 | )* |
25 | } |
26 | } |
27 | |
28 | /// Enables enter::block_on. |
29 | macro_rules! cfg_block_on { |
30 | ($($item:item)*) => { |
31 | $( |
32 | #[cfg(any( |
33 | feature = "fs" , |
34 | feature = "net" , |
35 | feature = "io-std" , |
36 | feature = "rt" , |
37 | ))] |
38 | $item |
39 | )* |
40 | } |
41 | } |
42 | |
43 | /// Enables internal `AtomicWaker` impl. |
44 | macro_rules! cfg_atomic_waker_impl { |
45 | ($($item:item)*) => { |
46 | $( |
47 | #[cfg(any( |
48 | feature = "net" , |
49 | feature = "process" , |
50 | feature = "rt" , |
51 | feature = "signal" , |
52 | feature = "time" , |
53 | ))] |
54 | #[cfg(not(loom))] |
55 | $item |
56 | )* |
57 | } |
58 | } |
59 | |
60 | macro_rules! cfg_aio { |
61 | ($($item:item)*) => { |
62 | $( |
63 | #[cfg(all(any(docsrs, target_os = "freebsd" ), feature = "net" ))] |
64 | #[cfg_attr(docsrs, |
65 | doc(cfg(all(target_os = "freebsd" , feature = "net" ))) |
66 | )] |
67 | $item |
68 | )* |
69 | } |
70 | } |
71 | |
72 | macro_rules! cfg_fs { |
73 | ($($item:item)*) => { |
74 | $( |
75 | #[cfg(feature = "fs" )] |
76 | #[cfg(not(tokio_wasi))] |
77 | #[cfg_attr(docsrs, doc(cfg(feature = "fs" )))] |
78 | $item |
79 | )* |
80 | } |
81 | } |
82 | |
83 | macro_rules! cfg_io_blocking { |
84 | ($($item:item)*) => { |
85 | $( #[cfg(any( |
86 | feature = "io-std" , |
87 | feature = "fs" , |
88 | all(windows, feature = "process" ), |
89 | ))] $item )* |
90 | } |
91 | } |
92 | |
93 | macro_rules! cfg_io_driver { |
94 | ($($item:item)*) => { |
95 | $( |
96 | #[cfg(any( |
97 | feature = "net" , |
98 | all(unix, feature = "process" ), |
99 | all(unix, feature = "signal" ), |
100 | ))] |
101 | #[cfg_attr(docsrs, doc(cfg(any( |
102 | feature = "net" , |
103 | all(unix, feature = "process" ), |
104 | all(unix, feature = "signal" ), |
105 | ))))] |
106 | $item |
107 | )* |
108 | } |
109 | } |
110 | |
111 | macro_rules! cfg_io_driver_impl { |
112 | ( $( $item:item )* ) => { |
113 | $( |
114 | #[cfg(any( |
115 | feature = "net" , |
116 | all(unix, feature = "process" ), |
117 | all(unix, feature = "signal" ), |
118 | ))] |
119 | $item |
120 | )* |
121 | } |
122 | } |
123 | |
124 | macro_rules! cfg_not_io_driver { |
125 | ($($item:item)*) => { |
126 | $( |
127 | #[cfg(not(any( |
128 | feature = "net" , |
129 | all(unix, feature = "process" ), |
130 | all(unix, feature = "signal" ), |
131 | )))] |
132 | $item |
133 | )* |
134 | } |
135 | } |
136 | |
137 | macro_rules! cfg_io_readiness { |
138 | ($($item:item)*) => { |
139 | $( |
140 | #[cfg(feature = "net" )] |
141 | $item |
142 | )* |
143 | } |
144 | } |
145 | |
146 | macro_rules! cfg_io_std { |
147 | ($($item:item)*) => { |
148 | $( |
149 | #[cfg(feature = "io-std" )] |
150 | #[cfg_attr(docsrs, doc(cfg(feature = "io-std" )))] |
151 | $item |
152 | )* |
153 | } |
154 | } |
155 | |
156 | macro_rules! cfg_io_util { |
157 | ($($item:item)*) => { |
158 | $( |
159 | #[cfg(feature = "io-util" )] |
160 | #[cfg_attr(docsrs, doc(cfg(feature = "io-util" )))] |
161 | $item |
162 | )* |
163 | } |
164 | } |
165 | |
166 | macro_rules! cfg_not_io_util { |
167 | ($($item:item)*) => { |
168 | $( #[cfg(not(feature = "io-util" ))] $item )* |
169 | } |
170 | } |
171 | |
172 | macro_rules! cfg_loom { |
173 | ($($item:item)*) => { |
174 | $( #[cfg(loom)] $item )* |
175 | } |
176 | } |
177 | |
178 | macro_rules! cfg_not_loom { |
179 | ($($item:item)*) => { |
180 | $( #[cfg(not(loom))] $item )* |
181 | } |
182 | } |
183 | |
184 | macro_rules! cfg_macros { |
185 | ($($item:item)*) => { |
186 | $( |
187 | #[cfg(feature = "macros" )] |
188 | #[cfg_attr(docsrs, doc(cfg(feature = "macros" )))] |
189 | $item |
190 | )* |
191 | } |
192 | } |
193 | |
194 | macro_rules! cfg_metrics { |
195 | ($($item:item)*) => { |
196 | $( |
197 | // For now, metrics is only disabled in loom tests. |
198 | // When stabilized, it might have a dedicated feature flag. |
199 | #[cfg(all(tokio_unstable, not(loom)))] |
200 | #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] |
201 | $item |
202 | )* |
203 | } |
204 | } |
205 | |
206 | macro_rules! cfg_not_metrics { |
207 | ($($item:item)*) => { |
208 | $( |
209 | #[cfg(not(all(tokio_unstable, not(loom))))] |
210 | $item |
211 | )* |
212 | } |
213 | } |
214 | |
215 | macro_rules! cfg_not_rt_and_metrics_and_net { |
216 | ($($item:item)*) => { |
217 | $( #[cfg(not(all(feature = "net" , feature = "rt" , all(tokio_unstable, not(loom)))))]$item )* |
218 | } |
219 | } |
220 | |
221 | macro_rules! cfg_net_or_process { |
222 | ($($item:item)*) => { |
223 | $( |
224 | #[cfg(any(feature = "net" , feature = "process" ))] |
225 | #[cfg_attr(docsrs, doc(cfg(any(feature = "net" , feature = "process" ))))] |
226 | $item |
227 | )* |
228 | } |
229 | } |
230 | |
231 | macro_rules! cfg_net { |
232 | ($($item:item)*) => { |
233 | $( |
234 | #[cfg(feature = "net" )] |
235 | #[cfg_attr(docsrs, doc(cfg(feature = "net" )))] |
236 | $item |
237 | )* |
238 | } |
239 | } |
240 | |
241 | macro_rules! cfg_net_unix { |
242 | ($($item:item)*) => { |
243 | $( |
244 | #[cfg(all(unix, feature = "net" ))] |
245 | #[cfg_attr(docsrs, doc(cfg(all(unix, feature = "net" ))))] |
246 | $item |
247 | )* |
248 | } |
249 | } |
250 | |
251 | macro_rules! cfg_net_windows { |
252 | ($($item:item)*) => { |
253 | $( |
254 | #[cfg(all(any(all(doc, docsrs), windows), feature = "net" ))] |
255 | #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "net" ))))] |
256 | $item |
257 | )* |
258 | } |
259 | } |
260 | |
261 | macro_rules! cfg_process { |
262 | ($($item:item)*) => { |
263 | $( |
264 | #[cfg(feature = "process" )] |
265 | #[cfg_attr(docsrs, doc(cfg(feature = "process" )))] |
266 | #[cfg(not(loom))] |
267 | #[cfg(not(tokio_wasi))] |
268 | $item |
269 | )* |
270 | } |
271 | } |
272 | |
273 | macro_rules! cfg_process_driver { |
274 | ($($item:item)*) => { |
275 | #[cfg(unix)] |
276 | #[cfg(not(loom))] |
277 | cfg_process! { $($item)* } |
278 | } |
279 | } |
280 | |
281 | macro_rules! cfg_not_process_driver { |
282 | ($($item:item)*) => { |
283 | $( |
284 | #[cfg(not(all(unix, not(loom), feature = "process" )))] |
285 | $item |
286 | )* |
287 | } |
288 | } |
289 | |
290 | macro_rules! cfg_signal { |
291 | ($($item:item)*) => { |
292 | $( |
293 | #[cfg(feature = "signal" )] |
294 | #[cfg_attr(docsrs, doc(cfg(feature = "signal" )))] |
295 | #[cfg(not(loom))] |
296 | #[cfg(not(tokio_wasi))] |
297 | $item |
298 | )* |
299 | } |
300 | } |
301 | |
302 | macro_rules! cfg_signal_internal { |
303 | ($($item:item)*) => { |
304 | $( |
305 | #[cfg(any(feature = "signal" , all(unix, feature = "process" )))] |
306 | #[cfg(not(loom))] |
307 | $item |
308 | )* |
309 | } |
310 | } |
311 | |
312 | macro_rules! cfg_signal_internal_and_unix { |
313 | ($($item:item)*) => { |
314 | #[cfg(unix)] |
315 | cfg_signal_internal! { $($item)* } |
316 | } |
317 | } |
318 | |
319 | macro_rules! cfg_not_signal_internal { |
320 | ($($item:item)*) => { |
321 | $( |
322 | #[cfg(any(loom, not(unix), not(any(feature = "signal" , all(unix, feature = "process" )))))] |
323 | $item |
324 | )* |
325 | } |
326 | } |
327 | |
328 | macro_rules! cfg_sync { |
329 | ($($item:item)*) => { |
330 | $( |
331 | #[cfg(feature = "sync" )] |
332 | #[cfg_attr(docsrs, doc(cfg(feature = "sync" )))] |
333 | $item |
334 | )* |
335 | } |
336 | } |
337 | |
338 | macro_rules! cfg_not_sync { |
339 | ($($item:item)*) => { |
340 | $( #[cfg(not(feature = "sync" ))] $item )* |
341 | } |
342 | } |
343 | |
344 | macro_rules! cfg_rt { |
345 | ($($item:item)*) => { |
346 | $( |
347 | #[cfg(feature = "rt" )] |
348 | #[cfg_attr(docsrs, doc(cfg(feature = "rt" )))] |
349 | $item |
350 | )* |
351 | } |
352 | } |
353 | |
354 | macro_rules! cfg_not_rt { |
355 | ($($item:item)*) => { |
356 | $( #[cfg(not(feature = "rt" ))] $item )* |
357 | } |
358 | } |
359 | |
360 | macro_rules! cfg_rt_multi_thread { |
361 | ($($item:item)*) => { |
362 | $( |
363 | #[cfg(all(feature = "rt-multi-thread" , not(tokio_wasi)))] |
364 | #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread" )))] |
365 | $item |
366 | )* |
367 | } |
368 | } |
369 | |
370 | macro_rules! cfg_not_rt_multi_thread { |
371 | ($($item:item)*) => { |
372 | $( #[cfg(not(feature = "rt-multi-thread" ))] $item )* |
373 | } |
374 | } |
375 | |
376 | macro_rules! cfg_taskdump { |
377 | ($($item:item)*) => { |
378 | $( |
379 | #[cfg(all( |
380 | tokio_unstable, |
381 | tokio_taskdump, |
382 | feature = "rt" , |
383 | target_os = "linux" , |
384 | any( |
385 | target_arch = "aarch64" , |
386 | target_arch = "x86" , |
387 | target_arch = "x86_64" |
388 | ) |
389 | ))] |
390 | $item |
391 | )* |
392 | }; |
393 | } |
394 | |
395 | macro_rules! cfg_not_taskdump { |
396 | ($($item:item)*) => { |
397 | $( |
398 | #[cfg(not(all( |
399 | tokio_unstable, |
400 | tokio_taskdump, |
401 | feature = "rt" , |
402 | target_os = "linux" , |
403 | any( |
404 | target_arch = "aarch64" , |
405 | target_arch = "x86" , |
406 | target_arch = "x86_64" |
407 | ) |
408 | )))] |
409 | $item |
410 | )* |
411 | }; |
412 | } |
413 | |
414 | macro_rules! cfg_test_util { |
415 | ($($item:item)*) => { |
416 | $( |
417 | #[cfg(feature = "test-util" )] |
418 | #[cfg_attr(docsrs, doc(cfg(feature = "test-util" )))] |
419 | $item |
420 | )* |
421 | } |
422 | } |
423 | |
424 | macro_rules! cfg_not_test_util { |
425 | ($($item:item)*) => { |
426 | $( #[cfg(not(feature = "test-util" ))] $item )* |
427 | } |
428 | } |
429 | |
430 | macro_rules! cfg_time { |
431 | ($($item:item)*) => { |
432 | $( |
433 | #[cfg(feature = "time" )] |
434 | #[cfg_attr(docsrs, doc(cfg(feature = "time" )))] |
435 | $item |
436 | )* |
437 | } |
438 | } |
439 | |
440 | macro_rules! cfg_not_time { |
441 | ($($item:item)*) => { |
442 | $( #[cfg(not(feature = "time" ))] $item )* |
443 | } |
444 | } |
445 | |
446 | macro_rules! cfg_trace { |
447 | ($($item:item)*) => { |
448 | $( |
449 | #[cfg(all(tokio_unstable, feature = "tracing" ))] |
450 | #[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "tracing" ))))] |
451 | $item |
452 | )* |
453 | }; |
454 | } |
455 | |
456 | macro_rules! cfg_unstable { |
457 | ($($item:item)*) => { |
458 | $( |
459 | #[cfg(tokio_unstable)] |
460 | #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] |
461 | $item |
462 | )* |
463 | }; |
464 | } |
465 | |
466 | macro_rules! cfg_not_trace { |
467 | ($($item:item)*) => { |
468 | $( |
469 | #[cfg(any(not(tokio_unstable), not(feature = "tracing" )))] |
470 | $item |
471 | )* |
472 | } |
473 | } |
474 | |
475 | macro_rules! cfg_coop { |
476 | ($($item:item)*) => { |
477 | $( |
478 | #[cfg(any( |
479 | feature = "fs" , |
480 | feature = "io-std" , |
481 | feature = "net" , |
482 | feature = "process" , |
483 | feature = "rt" , |
484 | feature = "signal" , |
485 | feature = "sync" , |
486 | feature = "time" , |
487 | ))] |
488 | $item |
489 | )* |
490 | } |
491 | } |
492 | |
493 | macro_rules! cfg_not_coop { |
494 | ($($item:item)*) => { |
495 | $( |
496 | #[cfg(not(any( |
497 | feature = "fs" , |
498 | feature = "io-std" , |
499 | feature = "net" , |
500 | feature = "process" , |
501 | feature = "rt" , |
502 | feature = "signal" , |
503 | feature = "sync" , |
504 | feature = "time" , |
505 | )))] |
506 | $item |
507 | )* |
508 | } |
509 | } |
510 | |
511 | macro_rules! cfg_has_atomic_u64 { |
512 | ($($item:item)*) => { |
513 | $( |
514 | #[cfg_attr( |
515 | not(tokio_no_target_has_atomic), |
516 | cfg(all(target_has_atomic = "64" , not(tokio_no_atomic_u64)) |
517 | ))] |
518 | #[cfg_attr( |
519 | tokio_no_target_has_atomic, |
520 | cfg(not(tokio_no_atomic_u64)) |
521 | )] |
522 | $item |
523 | )* |
524 | } |
525 | } |
526 | |
527 | macro_rules! cfg_not_has_atomic_u64 { |
528 | ($($item:item)*) => { |
529 | $( |
530 | #[cfg_attr( |
531 | not(tokio_no_target_has_atomic), |
532 | cfg(any(not(target_has_atomic = "64" ), tokio_no_atomic_u64) |
533 | ))] |
534 | #[cfg_attr( |
535 | tokio_no_target_has_atomic, |
536 | cfg(tokio_no_atomic_u64) |
537 | )] |
538 | $item |
539 | )* |
540 | } |
541 | } |
542 | |
543 | macro_rules! cfg_has_const_mutex_new { |
544 | ($($item:item)*) => { |
545 | $( |
546 | #[cfg(all( |
547 | not(all(loom, test)), |
548 | any( |
549 | feature = "parking_lot" , |
550 | not(tokio_no_const_mutex_new) |
551 | ) |
552 | ))] |
553 | $item |
554 | )* |
555 | } |
556 | } |
557 | |
558 | macro_rules! cfg_not_has_const_mutex_new { |
559 | ($($item:item)*) => { |
560 | $( |
561 | #[cfg(not(all( |
562 | not(all(loom, test)), |
563 | any( |
564 | feature = "parking_lot" , |
565 | not(tokio_no_const_mutex_new) |
566 | ) |
567 | )))] |
568 | $item |
569 | )* |
570 | } |
571 | } |
572 | |
573 | macro_rules! cfg_not_wasi { |
574 | ($($item:item)*) => { |
575 | $( |
576 | #[cfg(not(tokio_wasi))] |
577 | $item |
578 | )* |
579 | } |
580 | } |
581 | |
582 | macro_rules! cfg_is_wasm_not_wasi { |
583 | ($($item:item)*) => { |
584 | $( |
585 | #[cfg(tokio_wasm_not_wasi)] |
586 | $item |
587 | )* |
588 | } |
589 | } |
590 | |