mio/sys/
mod.rs

1//! Module with system specific types.
2//!
3//! Required types:
4//!
5//! * `Event`: a type alias for the system specific event, e.g. `kevent` or
6//!   `epoll_event`.
7//! * `event`: a module with various helper functions for `Event`, see
8//!   [`crate::event::Event`] for the required functions.
9//! * `Events`: collection of `Event`s, see [`crate::Events`].
10//! * `IoSourceState`: state for the `IoSource` type.
11//! * `Selector`: selector used to register event sources and poll for events,
12//!   see [`crate::Poll`] and [`crate::Registry`] for required methods.
13//! * `tcp` and `udp` modules: see the [`crate::net`] module.
14//! * `Waker`: see [`crate::Waker`].
15
16cfg_os_poll! {
17    macro_rules! debug_detail {
18        (
19            $type: ident ($event_type: ty), $test: path,
20            $($(#[$target: meta])* $libc: ident :: $flag: ident),+ $(,)*
21        ) => {
22            struct $type($event_type);
23
24            impl fmt::Debug for $type {
25                fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26                    let mut written_one = false;
27                    $(
28                        $(#[$target])*
29                        #[allow(clippy::bad_bit_mask)] // Apparently some flags are zero.
30                        {
31                            // Windows doesn't use `libc` but the `afd` module.
32                            if $test(&self.0, &$libc :: $flag) {
33                                if !written_one {
34                                    write!(f, "{}", stringify!($flag))?;
35                                    written_one = true;
36                                } else {
37                                    write!(f, "|{}", stringify!($flag))?;
38                                }
39                            }
40                        }
41                    )+
42                    if !written_one {
43                        write!(f, "(empty)")
44                    } else {
45                        Ok(())
46                    }
47                }
48            }
49        };
50    }
51}
52
53#[cfg(any(unix, target_os = "hermit"))]
54cfg_os_poll! {
55    mod unix;
56    #[allow(unused_imports)]
57    pub use self::unix::*;
58}
59
60#[cfg(windows)]
61cfg_os_poll! {
62    mod windows;
63    pub use self::windows::*;
64}
65
66#[cfg(target_os = "wasi")]
67cfg_os_poll! {
68    mod wasi;
69    pub(crate) use self::wasi::*;
70}
71
72cfg_not_os_poll! {
73    mod shell;
74    pub(crate) use self::shell::*;
75
76    #[cfg(unix)]
77    cfg_any_os_ext! {
78        mod unix;
79        #[cfg(feature = "os-ext")]
80        pub use self::unix::SourceFd;
81    }
82}