BorrowCheck › Rust language core
Async
Future and poll, Waker, Pin / Unpin, async fn desugaring, cancellation safety, the runtime.
The topic explains async Rust from the bottom up: the Future trait, polling it, and the executor that does the polling. The questions on Future and poll check that futures are lazy, what poll returns, .await outside an async context (E0728), and polling a completed future; the Waker subtopic covers who calls poll, how wake differs from wake_by_ref, and what a minimal executor loop looks like. The subtopic on Pin, Unpin and PhantomPinned covers what pinning promises, how pin! differs from Box::pin, and why a future from an async block cannot be pinned with Pin::new. The subtopic on async fn desugaring shows the state machine: its size, how it captures arguments and lifetimes, a recursive async fn (E0733), a guard held across an await point, and async fn in traits together with dyn. The subtopic on cancellation safety covers dropping a future, select!, timeout and abort. The subtopic on streams introduces the Stream trait as an asynchronous iterator: poll_next, the next method from StreamExt, the Unpin requirement, lazy adapters, timeout, throttle and merge, a stream over a channel and when it ends. The last subtopic is about the Tokio runtime: tasks and spawn, the Send requirement on futures, JoinHandle, and blocking code inside a task. The topic builds on concurrency and smart pointers.
52 questions: 22 basic, 27 intermediate, 3 advanced. 7 info pages, 3 sources.
Subtopics
FutureandpollWakerand the executorPin,Unpin,PhantomPinnedasync fndesugaring- Cancellation safety
- Streams:
StreamandStreamExt - Runtime: tasks,
spawn, blocking code
Previous: Concurrency · Next: Unsafe, UB, FFI