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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//! # Nuclei
//!
//! A proactive async runtime: thread-per-core shards that run tasks and
//! drive their own IO, timers and buffers. Every operation is completed for
//! the task that asked for it; no task waits for readiness and then makes
//! the call itself. IO runs on io_uring on Linux where the kernel allows it,
//! else on epoll; on kqueue on macOS and the BSDs; and on I/O completion
//! ports on Windows.
//!
//! [`spawn`], [`block_on`] and the rest place work on the process default
//! [`Runtime`], which starts on first use with no configuration; a
//! [`Builder`] sets every setting for a runtime of one's own.
//!
//! # What is where
//!
//! - [`runtime`]: runtimes, their builder and handles, `block_on`, tasks
//! placed on a worker one names
//! ([`RuntimeHandle::spawn_on_worker`], [`RuntimeHandle::on_each_worker`])
//! and values kept per worker ([`shard_local!`]).
//! - [`task`]: spawning, [`JoinSet`](task::JoinSet), abort handles, ids and
//! names, task-local values and yielding.
//! - [`net`]: TCP, UDP and Unix sockets, names, socket options and builders,
//! stream halves, `shut` and `abort`, and pipes.
//! - [`io`]: [`Handle`], async operations on std's own IO objects, and the
//! helpers every stream gets: reads and writes as futures, copies,
//! buffers, in-memory pipes, the standard streams and readiness; and the
//! buffers the owned calls lend the driver ([`io::IoBuf`],
//! [`io::AlignedBuf`], [`io::IoVecBuf`]).
//! - [`fs`]: files, whole-file calls, metadata and directories; IO at an
//! offset, direct IO, syncs, the space calls and advisory locks.
//! - [`time`]: sleeps on a millisecond wheel or to the microsecond,
//! timeouts, intervals and a clock tests can pause.
//! - [`sync`]: locks, semaphores, notifications, once-cells, channels and
//! cancellation tokens, for any executor; [`sync::local`], their cheaper
//! twins for the tasks of one shard; and [`sync::mesh`], channels between
//! every pair of a set of parties.
//! - [`process`] and [`signal`]: child processes, signals and console events.
//! - [`stats()`]: a snapshot of what every shard is doing, with poll times
//! when recorded and, with the `io-stats` feature, its IO counts and
//! latencies.
//! - [`select!`], [`join!`] and [`try_join!`] wait on several futures in one
//! task; `#[nuclei::main]`, `#[nuclei::test]` and `#[nuclei::bench]` run
//! an async function in the runtime.
//!
//! A call that needs the default runtime or the calling thread's shard
//! panics if that cannot start (the system refused its poller: no
//! descriptors or memory left); [`Builder::build`] and [`task::Builder`]
//! answer the error instead. [`Builder::build`] also checks every setting
//! first, and answers one out of range as `InvalidInput` naming it.
//!
//! The guide, a path from the first program to production with an example
//! that runs for every idea, is at <https://nuclei.rs/learn/>.
//!
//! ```no_run
//! use nuclei::net::TcpListener;
//!
//! #[nuclei::main]
//! async fn main() -> std::io::Result<()> {
//! let listener = TcpListener::bind("127.0.0.1:7000").await?;
//! loop {
//! let (stream, _) = listener.accept().await?;
//! nuclei::spawn(async move {
//! let mut buf = [0u8; 1024];
//! while let Ok(n @ 1..) = stream.recv(&mut buf).await {
//! if stream.send(&buf[..n]).await.is_err() {
//! break;
//! }
//! }
//! })
//! .detach();
//! }
//! }
//! ```
// A model-checking build (`--cfg loom`) compiles the loom models and leaves
// the ordinary tests out, so the helpers only those tests use go unused.
// No unwrap, expect or panic outside a documented contract, each marked
// where it is; every unsafe block names what it rests on. Tests and the
// model-checking build may assert.
/// The proactor's configuration: the io_uring settings of every shard and the default backend.
/// Child processes: spawn one, wait for its exit and talk to it through async pipes.
/// nuclei's own runtime: shards, tasks, `block_on`, `spawn` and the blocking pool.
/// Signals (unix) and console control events (Windows), as streams.
/// Runtime-independent synchronization primitives: futures and wakers only, usable from any executor.
/// Tasks: spawning, their handles and ids, cancellation from anywhere, and yielding.
/// Time: sleeping, timeouts and intervals on the shard's timer wheel.
compile_error!;
pub use ;
pub use ;
pub use TcpStreamGenerator;
pub use ;
pub use ;
pub use ;
pub use stats;
pub use ;