aboutsummaryrefslogtreecommitdiff
path: root/src/macros/mod.rs
blob: 2275ed9fa01099cc09c35c38f3aa888ddaa771fc (plain)
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
//! Macros to ease conditional code based on enabled features.

// Depending on the features not all macros are used.
#![allow(unused_macros)]

/// Feature `os-poll` enabled.
macro_rules! cfg_os_poll {
    ($($item:item)*) => {
        $(
            #[cfg(feature = "os-poll")]
            #[cfg_attr(docsrs, doc(cfg(feature = "os-poll")))]
            $item
        )*
    }
}

/// Feature `os-poll` disabled.
macro_rules! cfg_not_os_poll {
    ($($item:item)*) => {
        $(
            #[cfg(not(feature = "os-poll"))]
            $item
        )*
    }
}

/// One of the `tcp`, `udp`, `uds` features enabled.
#[cfg(unix)]
macro_rules! cfg_net {
    ($($item:item)*) => {
        $(
            #[cfg(any(feature = "tcp", feature = "udp", feature = "uds"))]
            #[cfg_attr(docsrs, doc(cfg(any(feature = "tcp", feature = "udp", feature = "uds"))))]
            $item
        )*
    }
}

/// One of the features enabled that needs `IoSource`. That is `tcp`, or `udp`,
/// or on Unix `uds` or `pipe`.
macro_rules! cfg_io_source {
    ($($item:item)*) => {
        $(
            #[cfg(any(feature = "tcp", feature = "udp", all(unix, any(feature = "uds",  feature = "pipe"))))]
            #[cfg_attr(docsrs, doc(any(feature = "tcp", feature = "udp", all(unix, any(feature = "uds",  feature = "pipe")))))]
            $item
        )*
    }
}

/// One of the `tcp`, `udp` features enabled.
#[cfg(windows)]
macro_rules! cfg_net {
    ($($item:item)*) => {
        $(
            #[cfg(any(feature = "tcp", feature = "udp"))]
            #[cfg_attr(docsrs, doc(cfg(any(feature = "tcp", feature = "udp"))))]
            $item
        )*
    }
}

/// Feature `tcp` enabled.
macro_rules! cfg_tcp {
    ($($item:item)*) => {
        $(
            #[cfg(feature = "tcp")]
            #[cfg_attr(docsrs, doc(cfg(feature = "tcp")))]
            $item
        )*
    }
}

/// Feature `udp` enabled.
macro_rules! cfg_udp {
    ($($item:item)*) => {
        $(
            #[cfg(feature = "udp")]
            #[cfg_attr(docsrs, doc(cfg(feature = "udp")))]
            $item
        )*
    }
}

/// Feature `uds` enabled.
#[cfg(unix)]
macro_rules! cfg_uds {
    ($($item:item)*) => {
        $(
            #[cfg(feature = "uds")]
            #[cfg_attr(docsrs, doc(cfg(feature = "uds")))]
            $item
        )*
    }
}

/// Feature `pipe` enabled.
#[cfg(unix)]
macro_rules! cfg_pipe {
    ($($item:item)*) => {
        $(
            #[cfg(feature = "pipe")]
            #[cfg_attr(docsrs, doc(cfg(feature = "pipe")))]
            $item
        )*
    }
}

/// Feature `os-util` enabled, or one of the features that need `os-util`.
#[cfg(unix)]
macro_rules! cfg_any_os_util {
    ($($item:item)*) => {
        $(
            #[cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "uds", feature = "pipe"))]
            #[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "uds", feature = "pipe"))))]
            $item
        )*
    }
}

/// Feature `os-util` enabled, or one of the features that need `os-util`.
#[cfg(windows)]
macro_rules! cfg_any_os_util {
    ($($item:item)*) => {
        $(
            #[cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "pipe"))]
            #[cfg_attr(docsrs, doc(cfg(any(feature = "os-util", feature = "tcp", feature = "udp", feature = "pipe"))))]
            $item
        )*
    }
}