Files
tokio/tokio/src/macros/cfg.rs
T

501 lines
11 KiB
Rust
Raw Normal View History

2019-11-18 07:00:55 -08:00
#![allow(unused_macros)]
2020-11-11 09:28:21 -08:00
macro_rules! feature {
(
#![$meta:meta]
$($item:item)*
) => {
$(
#[cfg($meta)]
#[cfg_attr(docsrs, doc(cfg($meta)))]
$item
)*
}
}
/// Enables enter::block_on.
2020-04-24 06:25:48 -06:00
macro_rules! cfg_block_on {
($($item:item)*) => {
$(
#[cfg(any(
feature = "fs",
feature = "net",
2020-04-24 06:25:48 -06:00
feature = "io-std",
2020-10-13 06:13:23 +09:00
feature = "rt",
2020-04-24 06:25:48 -06:00
))]
$item
)*
}
}
/// Enables internal `AtomicWaker` impl.
macro_rules! cfg_atomic_waker_impl {
($($item:item)*) => {
$(
#[cfg(any(
feature = "net",
feature = "process",
2020-10-13 06:13:23 +09:00
feature = "rt",
feature = "signal",
feature = "time",
))]
#[cfg(not(loom))]
$item
)*
}
}
2021-09-15 10:55:50 -06:00
macro_rules! cfg_aio {
($($item:item)*) => {
$(
#[cfg(all(any(docsrs, target_os = "freebsd"), feature = "net"))]
#[cfg_attr(docsrs,
doc(cfg(all(target_os = "freebsd", feature = "net")))
)]
$item
)*
}
}
2019-11-18 07:00:55 -08:00
macro_rules! cfg_fs {
2019-11-22 09:56:08 -08:00
($($item:item)*) => {
$(
#[cfg(feature = "fs")]
#[cfg(not(target_os = "wasi"))]
2019-11-22 09:56:08 -08:00
#[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
$item
)*
}
2019-11-18 07:00:55 -08:00
}
macro_rules! cfg_io_blocking {
($($item:item)*) => {
$( #[cfg(any(
feature = "io-std",
feature = "fs",
all(windows, feature = "process"),
))] $item )*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_io_driver {
($($item:item)*) => {
2019-11-22 09:56:08 -08:00
$(
#[cfg(any(
feature = "net",
all(unix, feature = "process"),
all(unix, feature = "signal"),
))]
#[cfg_attr(docsrs, doc(cfg(any(
feature = "net",
all(unix, feature = "process"),
all(unix, feature = "signal"),
))))]
2019-11-22 09:56:08 -08:00
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_io_driver_impl {
( $( $item:item )* ) => {
$(
#[cfg(any(
feature = "net",
all(unix, feature = "process"),
all(unix, feature = "signal"),
))]
$item
)*
}
}
2019-11-18 07:00:55 -08:00
macro_rules! cfg_not_io_driver {
($($item:item)*) => {
2019-11-22 09:56:08 -08:00
$(
#[cfg(not(any(
feature = "net",
all(unix, feature = "process"),
all(unix, feature = "signal"),
)))]
2019-11-22 09:56:08 -08:00
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_io_readiness {
($($item:item)*) => {
$(
#[cfg(feature = "net")]
$item
)*
}
}
2019-11-18 07:00:55 -08:00
macro_rules! cfg_io_std {
($($item:item)*) => {
2019-11-22 09:56:08 -08:00
$(
#[cfg(feature = "io-std")]
#[cfg_attr(docsrs, doc(cfg(feature = "io-std")))]
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_io_util {
($($item:item)*) => {
2019-11-22 09:56:08 -08:00
$(
#[cfg(feature = "io-util")]
#[cfg_attr(docsrs, doc(cfg(feature = "io-util")))]
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_not_io_util {
($($item:item)*) => {
$( #[cfg(not(feature = "io-util"))] $item )*
}
}
macro_rules! cfg_loom {
($($item:item)*) => {
$( #[cfg(loom)] $item )*
}
}
macro_rules! cfg_not_loom {
($($item:item)*) => {
$( #[cfg(not(loom))] $item )*
}
}
macro_rules! cfg_macros {
($($item:item)*) => {
$(
#[cfg(feature = "macros")]
2019-11-22 09:56:08 -08:00
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
2019-11-18 07:00:55 -08:00
$item
)*
}
}
2022-01-21 22:17:38 -08:00
macro_rules! cfg_metrics {
($($item:item)*) => {
$(
2022-02-07 17:06:03 +08:00
// For now, metrics is only disabled in loom tests.
// When stabilized, it might have a dedicated feature flag.
#[cfg(all(tokio_unstable, not(loom)))]
2022-01-21 22:17:38 -08:00
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
$item
)*
}
}
2022-01-21 22:17:38 -08:00
macro_rules! cfg_not_metrics {
($($item:item)*) => {
$(
2022-02-07 17:06:03 +08:00
#[cfg(not(all(tokio_unstable, not(loom))))]
$item
)*
}
}
macro_rules! cfg_not_rt_and_metrics_and_net {
($($item:item)*) => {
$( #[cfg(not(all(feature = "net", feature = "rt", all(tokio_unstable, not(loom)))))]$item )*
}
}
macro_rules! cfg_net_or_process {
($($item:item)*) => {
$(
#[cfg(any(feature = "net", feature = "process"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "net", feature = "process"))))]
$item
)*
}
}
macro_rules! cfg_net {
($($item:item)*) => {
$(
#[cfg(feature = "net")]
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
$item
)*
}
}
macro_rules! cfg_net_unix {
($($item:item)*) => {
$(
#[cfg(all(unix, feature = "net"))]
2021-08-24 14:57:23 +02:00
#[cfg_attr(docsrs, doc(cfg(all(unix, feature = "net"))))]
$item
)*
}
}
macro_rules! cfg_net_windows {
($($item:item)*) => {
$(
#[cfg(all(any(all(doc, docsrs), windows), feature = "net"))]
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "net"))))]
$item
)*
}
}
2019-11-18 07:00:55 -08:00
macro_rules! cfg_process {
($($item:item)*) => {
$(
#[cfg(feature = "process")]
2019-11-22 09:56:08 -08:00
#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
2019-11-18 07:00:55 -08:00
#[cfg(not(loom))]
#[cfg(not(target_os = "wasi"))]
2019-11-18 07:00:55 -08:00
$item
)*
}
}
macro_rules! cfg_process_driver {
($($item:item)*) => {
#[cfg(unix)]
#[cfg(not(loom))]
cfg_process! { $($item)* }
}
}
macro_rules! cfg_not_process_driver {
($($item:item)*) => {
$(
#[cfg(not(all(unix, not(loom), feature = "process")))]
$item
)*
}
}
2019-11-18 07:00:55 -08:00
macro_rules! cfg_signal {
($($item:item)*) => {
$(
#[cfg(feature = "signal")]
2019-11-25 14:32:55 -08:00
#[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
2019-11-18 07:00:55 -08:00
#[cfg(not(loom))]
#[cfg(not(target_os = "wasi"))]
2019-11-18 07:00:55 -08:00
$item
)*
}
}
macro_rules! cfg_signal_internal {
($($item:item)*) => {
$(
#[cfg(any(feature = "signal", all(unix, feature = "process")))]
#[cfg(not(loom))]
$item
)*
}
}
macro_rules! cfg_not_signal_internal {
($($item:item)*) => {
$(
#[cfg(any(loom, not(unix), not(any(feature = "signal", all(unix, feature = "process")))))]
$item
)*
}
}
2019-11-18 07:00:55 -08:00
macro_rules! cfg_sync {
($($item:item)*) => {
2019-11-25 14:32:55 -08:00
$(
#[cfg(feature = "sync")]
#[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_not_sync {
($($item:item)*) => {
$( #[cfg(not(feature = "sync"))] $item )*
}
}
2020-10-13 06:13:23 +09:00
macro_rules! cfg_rt {
($($item:item)*) => {
$(
2020-10-13 06:13:23 +09:00
#[cfg(feature = "rt")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
$item
)*
}
}
2020-10-13 06:13:23 +09:00
macro_rules! cfg_not_rt {
($($item:item)*) => {
2020-10-13 06:13:23 +09:00
$( #[cfg(not(feature = "rt"))] $item )*
2019-11-18 07:00:55 -08:00
}
}
2020-10-13 06:13:23 +09:00
macro_rules! cfg_rt_multi_thread {
($($item:item)*) => {
$(
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
2020-10-13 06:13:23 +09:00
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
$item
)*
}
}
2020-10-13 06:13:23 +09:00
macro_rules! cfg_not_rt_multi_thread {
2019-11-18 07:00:55 -08:00
($($item:item)*) => {
2020-10-13 06:13:23 +09:00
$( #[cfg(not(feature = "rt-multi-thread"))] $item )*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_test_util {
($($item:item)*) => {
2019-11-25 14:32:55 -08:00
$(
#[cfg(feature = "test-util")]
#[cfg_attr(docsrs, doc(cfg(feature = "test-util")))]
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_not_test_util {
($($item:item)*) => {
$( #[cfg(not(feature = "test-util"))] $item )*
}
}
macro_rules! cfg_time {
($($item:item)*) => {
2019-11-25 14:32:55 -08:00
$(
#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
$item
)*
2019-11-18 07:00:55 -08:00
}
}
macro_rules! cfg_not_time {
($($item:item)*) => {
$( #[cfg(not(feature = "time"))] $item )*
}
}
macro_rules! cfg_trace {
($($item:item)*) => {
$(
#[cfg(all(tokio_unstable, feature = "tracing"))]
#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "tracing"))))]
$item
)*
2021-12-15 00:04:19 +02:00
};
}
2022-02-15 01:37:40 -08:00
macro_rules! cfg_unstable {
($($item:item)*) => {
$(
#[cfg(tokio_unstable)]
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
$item
)*
};
}
macro_rules! cfg_not_trace {
($($item:item)*) => {
$(
#[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
$item
)*
}
}
2020-05-06 19:02:07 -07:00
macro_rules! cfg_coop {
($($item:item)*) => {
$(
#[cfg(any(
feature = "fs",
feature = "io-std",
feature = "net",
2020-05-06 19:02:07 -07:00
feature = "process",
2020-10-13 06:13:23 +09:00
feature = "rt",
feature = "signal",
2020-05-06 19:02:07 -07:00
feature = "sync",
feature = "time",
2020-05-06 19:02:07 -07:00
))]
$item
)*
}
}
macro_rules! cfg_not_coop {
($($item:item)*) => {
$(
#[cfg(not(any(
feature = "fs",
feature = "io-std",
feature = "net",
feature = "process",
feature = "rt",
feature = "signal",
feature = "sync",
feature = "time",
)))]
$item
)*
}
}
macro_rules! cfg_has_atomic_u64 {
($($item:item)*) => {
$(
#[cfg(not(any(
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "riscv32",
target_family = "wasm"
)))]
$item
)*
}
}
macro_rules! cfg_not_has_atomic_u64 {
($($item:item)*) => {
$(
#[cfg(any(
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "riscv32",
target_family = "wasm"
))]
$item
)*
}
}
macro_rules! cfg_not_wasi {
($($item:item)*) => {
$(
#[cfg(not(target_os = "wasi"))]
$item
)*
}
}
macro_rules! cfg_is_wasm_not_wasi {
($($item:item)*) => {
$(
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
$item
)*
}
}