net_io/driver.rs
1//! Driver selection.
2//!
3//! The blocking pool ships in `0.3.0`; the reactor (epoll, kqueue, IOCP) in
4//! `0.5.0`; io_uring after `1.0.0`. The `Driver` trait itself becomes public at
5//! `0.5.0`.
6
7/// Which driver moves the bytes.
8///
9/// `Auto` picks the reactor where it is built and available, otherwise the
10/// blocking pool.
11///
12/// # Examples
13///
14/// ```
15/// assert_eq!(net_io::DriverKind::default(), net_io::DriverKind::Auto);
16/// ```
17#[non_exhaustive]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
19pub enum DriverKind {
20 /// A bounded pool of threads, one connection per thread.
21 Blocking,
22 /// One event loop per worker (epoll, kqueue, IOCP); from `0.5.0`.
23 Reactor,
24 /// io_uring on Linux; after `1.0.0`.
25 Uring,
26 /// The reactor where available, otherwise the blocking pool.
27 #[default]
28 Auto,
29}
30
31impl DriverKind {
32 /// The driver `Auto` resolves to in this build.
33 pub(crate) fn resolve(self) -> DriverKind {
34 match self {
35 // The reactor arrives in 0.5.0; until then everything runs on the blocking pool.
36 DriverKind::Auto => DriverKind::Blocking,
37 other => other,
38 }
39 }
40}