1//! Macros to ease conditional code based on enabled features.
2
3// Depending on the features not all macros are used.
4#![allow(unused_macros)]
5
6/// The `os-poll` feature is enabled.
7macro_rules! cfg_os_poll {
8 ($($item:item)*) => {
9 $(
10 #[cfg(feature = "os-poll")]
11 #[cfg_attr(docsrs, doc(cfg(feature = "os-poll")))]
12 $item
13 )*
14 }
15}
16
17/// The `os-poll` feature is disabled.
18macro_rules! cfg_not_os_poll {
19 ($($item:item)*) => {
20 $(
21 #[cfg(not(feature = "os-poll"))]
22 $item
23 )*
24 }
25}
26
27/// The `os-ext` feature is enabled.
28macro_rules! cfg_os_ext {
29 ($($item:item)*) => {
30 $(
31 #[cfg(feature = "os-ext")]
32 #[cfg_attr(docsrs, doc(cfg(feature = "os-ext")))]
33 $item
34 )*
35 }
36}
37
38/// The `net` feature is enabled.
39macro_rules! cfg_net {
40 ($($item:item)*) => {
41 $(
42 #[cfg(feature = "net")]
43 #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
44 $item
45 )*
46 }
47}
48
49/// One of the features enabled that needs `IoSource`. That is `net` or `os-ext`
50/// on Unix (for `pipe`).
51macro_rules! cfg_io_source {
52 ($($item:item)*) => {
53 $(
54 #[cfg(any(feature = "net", all(unix, feature = "os-ext")))]
55 #[cfg_attr(docsrs, doc(cfg(any(feature = "net", all(unix, feature = "os-ext")))))]
56 $item
57 )*
58 }
59}
60
61/// The `os-ext` feature is enabled, or one of the features that need `os-ext`.
62macro_rules! cfg_any_os_ext {
63 ($($item:item)*) => {
64 $(
65 #[cfg(any(feature = "os-ext", feature = "net"))]
66 #[cfg_attr(docsrs, doc(cfg(any(feature = "os-ext", feature = "net"))))]
67 $item
68 )*
69 }
70}
71
72macro_rules! trace {
73 ($($t:tt)*) => {
74 log!(trace, $($t)*)
75 }
76}
77
78macro_rules! warn {
79 ($($t:tt)*) => {
80 log!(warn, $($t)*)
81 }
82}
83
84macro_rules! error {
85 ($($t:tt)*) => {
86 log!(error, $($t)*)
87 }
88}
89
90macro_rules! log {
91 ($level: ident, $($t:tt)*) => {
92 #[cfg(feature = "log")]
93 { log::$level!($($t)*) }
94 // Silence unused variables warnings.
95 #[cfg(not(feature = "log"))]
96 { if false { let _ = ( $($t)* ); } }
97 }
98}
99