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