Skip to main content

monocoque_core/rt/
mod.rs

1//! Runtime facade: the single place that names a concrete async runtime.
2//!
3//! Monocoque's whole socket stack is generic over the I/O traits from
4//! `compio::io` (an owned-buffer, completion-style interface that maps cleanly
5//! onto `io_uring`). Those traits, and the buffer types in `compio::buf`, are the
6//! abstraction the rest of the code is written against, and they stay the same
7//! no matter which runtime drives the sockets.
8//!
9//! What actually differs between runtimes is small: how you open a connection,
10//! how you spawn a task, and how you arm a timer. This module collects exactly
11//! those pieces behind one set of names so the rest of the crate (and the ZMTP
12//! layer above it) never mentions `compio`, `tokio`, or `smol` directly.
13//!
14//! Each backend lives in its own file and is exposed under one shared name,
15//! `backend`, selected by a Cargo feature. Only one is ever compiled:
16//!
17//! - `runtime-compio` (default): native `io_uring` through compio (see `compio.rs`).
18//! - `runtime-tokio`: a thin adapter over tokio streams (see `tokio.rs`).
19//! - `runtime-smol`: a thin adapter over smol's async-io streams (see `smol.rs`).
20//!
21//! The tokio and smol adapters implement the same `compio::io` traits by reading
22//! straight into the owned buffer's memory, so there is no extra copy on the
23//! data path. Exactly one of the three must be enabled.
24
25#[cfg(all(feature = "runtime-compio", feature = "runtime-tokio"))]
26compile_error!(
27    "monocoque: enable exactly one runtime backend, not both \
28     (`runtime-compio` or `runtime-tokio`)"
29);
30
31#[cfg(all(feature = "runtime-compio", feature = "runtime-smol"))]
32compile_error!(
33    "monocoque: enable exactly one runtime backend, not both \
34     (`runtime-compio` or `runtime-smol`)"
35);
36
37#[cfg(all(feature = "runtime-tokio", feature = "runtime-smol"))]
38compile_error!(
39    "monocoque: enable exactly one runtime backend, not both \
40     (`runtime-tokio` or `runtime-smol`)"
41);
42
43#[cfg(not(any(
44    feature = "runtime-compio",
45    feature = "runtime-tokio",
46    feature = "runtime-smol"
47)))]
48compile_error!(
49    "monocoque: no runtime backend selected; enable `runtime-compio` (default), \
50     `runtime-tokio`, or `runtime-smol`"
51);
52
53// Exactly one backend file is compiled and re-exported under `backend`. The
54// tokio/smol modules are additionally gated on the absence of higher-priority
55// backends so that when several features are on at once, the `compile_error!`
56// above is the message the user sees rather than a duplicate `backend`
57// definition.
58
59#[cfg(feature = "runtime-compio")]
60#[path = "compio.rs"]
61mod backend;
62
63#[cfg(all(feature = "runtime-tokio", not(feature = "runtime-compio")))]
64#[path = "tokio.rs"]
65mod backend;
66
67#[cfg(all(
68    feature = "runtime-smol",
69    not(feature = "runtime-compio"),
70    not(feature = "runtime-tokio")
71))]
72#[path = "smol.rs"]
73mod backend;
74
75pub use backend::*;