Skip to content

Commit 4774453

Browse files
DavidLiedleclaude
andcommitted
Add full mdBook content for Rust at the Limit
Twelve chapters covering lifetimes, variance, HRTB, async internals, async lifetimes, Pin, async traits, error messages decoded, working patterns, and the two cases of compiler/programmer disagreement. Includes book.toml, GitHub Pages deploy workflow (peaceiris/actions-mdbook), README, bibliography, and CC0 license page. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4d3681d commit 4774453

19 files changed

Lines changed: 2597 additions & 0 deletions

.github/workflows/deploy.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Deploy mdBook to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: pages
16+
cancel-in-progress: false
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Setup mdBook
25+
uses: peaceiris/actions-mdbook@v2
26+
with:
27+
mdbook-version: 'latest'
28+
29+
- name: Build book
30+
run: mdbook build
31+
32+
- name: Setup Pages
33+
uses: actions/configure-pages@v5
34+
35+
- name: Upload artifact
36+
uses: actions/upload-pages-artifact@v3
37+
with:
38+
path: ./book
39+
40+
deploy:
41+
needs: build
42+
runs-on: ubuntu-latest
43+
environment:
44+
name: github-pages
45+
url: ${{ steps.deployment.outputs.page_url }}
46+
steps:
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
book/
2+
.DS_Store

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Rust at the Limit
2+
3+
**The four corners of Rust where ordinary intuition stops working.**
4+
5+
**[Read online at cloudstreet-dev.github.io/Rust-at-the-Limit](https://cloudstreet-dev.github.io/Rust-at-the-Limit/)**
6+
7+
## About This Book
8+
9+
Async, lifetimes, `Pin`, higher-rank trait bounds, variance — the parts of Rust where the type system stops feeling helpful and starts feeling like an antagonist.
10+
11+
This book is for engineers who have already cleared the borrow checker and hit the next wall. The error messages are paragraphs long. The type system has opinions about variance that they don't share. Async functions silently impose constraints they didn't sign up for. `Pin` exists.
12+
13+
The book takes the reader into that territory deliberately, with a guide rather than a tutorial. Tone is direct, technical, occasionally sympathetic, never condescending.
14+
15+
## Table of Contents
16+
17+
### Part I: The Type System's Edges
18+
- [Past the Borrow Checker](src/introduction.md)
19+
- [Lifetimes Are Not What You Think](src/ch01-lifetimes.md)
20+
- [Variance](src/ch02-variance.md)
21+
- [Higher-Rank Trait Bounds](src/ch03-hrtb.md)
22+
23+
### Part II: Async, From the Inside
24+
- [Async Internals](src/ch04-async-internals.md)
25+
- [Async and Lifetimes Collide](src/ch05-async-lifetimes.md)
26+
- [Pin and Why It Has To Exist](src/ch06-pin.md)
27+
- [The Async Trait Problem](src/ch07-async-trait.md)
28+
29+
### Part III: Survival
30+
- [Error Messages, Decoded](src/ch08-error-messages.md)
31+
- [Patterns That Work](src/ch09-patterns.md)
32+
33+
### Part IV: Disagreement
34+
- [When the Type System Is Right and You're Wrong](src/ch10-compiler-right.md)
35+
- [When the Type System Is Wrong and You're Right](src/ch11-escape-hatches.md)
36+
37+
## Building Locally
38+
39+
```sh
40+
cargo install mdbook
41+
mdbook serve --open
42+
```
43+
44+
## License
45+
46+
CC0 1.0 Universal — public domain dedication. Take it, fork it, ship it, claim it as your own. See [LICENSE](LICENSE).

book.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[book]
2+
title = "Rust at the Limit"
3+
authors = ["Claude Code"]
4+
description = "Async, lifetimes, Pin, higher-rank trait bounds, variance — the parts of Rust where the type system stops feeling helpful and starts feeling like an antagonist. A survival guide to the four corners of Rust where ordinary intuition stops working."
5+
language = "en"
6+
src = "src"
7+
8+
[build]
9+
build-dir = "book"
10+
11+
[output.html]
12+
git-repository-url = "https://github.com/cloudstreet-dev/Rust-at-the-Limit"
13+
edit-url-template = "https://github.com/cloudstreet-dev/Rust-at-the-Limit/edit/main/{path}"
14+
site-url = "/Rust-at-the-Limit/"
15+
default-theme = "navy"
16+
preferred-dark-theme = "navy"
17+
18+
[output.html.fold]
19+
enable = true
20+
level = 0
21+
22+
[output.html.search]
23+
enable = true
24+
limit-results = 30
25+
teaser-word-count = 30
26+
use-boolean-and = true
27+
boost-title = 2
28+
boost-hierarchy = 1
29+
boost-paragraph = 1
30+
expand = true
31+
heading-split-level = 3

src/SUMMARY.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Summary
2+
3+
[Past the Borrow Checker](introduction.md)
4+
5+
---
6+
7+
# Part I: The Type System's Edges
8+
9+
- [Lifetimes Are Not What You Think](ch01-lifetimes.md)
10+
- [Variance](ch02-variance.md)
11+
- [Higher-Rank Trait Bounds](ch03-hrtb.md)
12+
13+
# Part II: Async, From the Inside
14+
15+
- [Async Internals](ch04-async-internals.md)
16+
- [Async and Lifetimes Collide](ch05-async-lifetimes.md)
17+
- [Pin and Why It Has To Exist](ch06-pin.md)
18+
- [The Async Trait Problem](ch07-async-trait.md)
19+
20+
# Part III: Survival
21+
22+
- [Error Messages, Decoded](ch08-error-messages.md)
23+
- [Patterns That Work](ch09-patterns.md)
24+
25+
# Part IV: Disagreement
26+
27+
- [When the Type System Is Right and You're Wrong](ch10-compiler-right.md)
28+
- [When the Type System Is Wrong and You're Right](ch11-escape-hatches.md)
29+
30+
---
31+
32+
[Bibliography and Sources](bibliography.md)
33+
[License](license.md)

src/bibliography.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Bibliography and Sources
2+
3+
The writing on the material in this book is mostly scattered: official documentation, RFCs, blog posts by Rust team members, and a few books. Here are the sources this book drew on, organized roughly by chapter.
4+
5+
## Official documentation
6+
7+
- *The Rust Programming Language*[doc.rust-lang.org/book](https://doc.rust-lang.org/book/). The prerequisite. If anything in this book felt like it skipped the basics, the basics are here.
8+
- *The Rust Reference*[doc.rust-lang.org/reference](https://doc.rust-lang.org/reference/). The formal description of the language. Dense, accurate, occasionally the only authoritative source for an obscure question.
9+
- *The Rustonomicon*[doc.rust-lang.org/nomicon](https://doc.rust-lang.org/nomicon/). Subtitle: *The Dark Arts of Advanced and Unsafe Rust Programming*. Mostly about unsafe code, but the chapters on subtyping, variance, and lifetimes are the canonical references for chapters 1 and 2 of this book.
10+
- *Asynchronous Programming in Rust*[rust-lang.github.io/async-book](https://rust-lang.github.io/async-book/). The official introduction to async. The chapter on the executor model and `Pin` is particularly good.
11+
12+
## Posts by Rust team members and async working group
13+
14+
- **Niko Matsakis** ([smallcultfollowing.com/babysteps](https://smallcultfollowing.com/babysteps/)) — the canonical source for type system internals. Posts on lifetime inference, HRTB, async traits, and the implementation of NLL (non-lexical lifetimes) are essential reading.
15+
- **Aaron Turon** ([aturon.github.io/blog](https://aturon.github.io/blog/)) — laid the foundation for Rust's async model in 2016. The posts on zero-cost futures, abstraction without overhead, and the design of trait objects are still relevant.
16+
- **Withoutboats** ([without.boats](https://without.boats/)) — the design history of `Pin`, the early thinking on async, and several posts on what the language could have been. Disagrees with later async direction in places; worth reading regardless.
17+
- **Ralf Jung** ([ralfj.de/blog](https://www.ralfj.de/blog/)) — the formal model of Rust's memory and aliasing. Stacked Borrows, Tree Borrows, and Miri all originate here. Essential if you write unsafe.
18+
- **Alice Ryhl** ([ryhl.io/blog](https://ryhl.io/blog/)) — practical async patterns. *Actors with Tokio* is the canonical reference for the actor pattern; *Async: What is blocking?* is the canonical reference for the blocking-vs-async distinction.
19+
- The [Rust async working group's vision document](https://rust-lang.github.io/wg-async/vision.html) — the roadmap for async Rust as of 2026.
20+
21+
## Books
22+
23+
- *Rust for Rustaceans* by Jon Gjengset (No Starch Press, 2021). The closest thing to a prerequisite for this book in print form. Covers async, lifetimes, and unsafe at the level of someone who is past the basics but not yet at the limits.
24+
- *Programming Rust* (2nd ed.) by Jim Blandy, Jason Orendorff, Leonora Tindall (O'Reilly, 2021). Comprehensive reference, treats lifetimes carefully, has a useful chapter on async.
25+
- *Zero To Production In Rust* by Luca Palmieri (self-published, ongoing). Async Rust applied to a real production system. Worth reading for the patterns it shows by example.
26+
27+
## Videos
28+
29+
- Jon Gjengset's [Crust of Rust](https://www.youtube.com/playlist?list=PLqbS7AVVErFiWDOAVrPt7aYmnuuOLYvOa) series — long-form livecoding walking through advanced Rust topics. The episodes on async, `Pin`, and lifetimes are excellent supplements to the corresponding chapters here.
30+
- The [RustConf](https://www.youtube.com/@rustvideos) talks on async internals from various years. Search for "async" plus "Niko Matsakis" or "Tyler Mandry" or "Eric Holk."
31+
32+
## RFCs
33+
34+
The relevant RFCs for the material in this book:
35+
36+
- [RFC 0066](https://rust-lang.github.io/rfcs/0066-better-temporary-lifetimes.html) — temporary lifetimes.
37+
- [RFC 1214](https://rust-lang.github.io/rfcs/1214-projections-lifetimes-and-wf.html) — projections, lifetimes, and well-formedness.
38+
- [RFC 2349](https://rust-lang.github.io/rfcs/2349-pin.html)`Pin`.
39+
- [RFC 2394](https://rust-lang.github.io/rfcs/2394-async_await.html)`async`/`await` syntax.
40+
- [RFC 2592](https://rust-lang.github.io/rfcs/2592-futures.html) — the `Future` trait in `std`.
41+
- [RFC 3185](https://rust-lang.github.io/rfcs/3185-static-async-fn-in-trait.html)`async fn` in traits, the static-dispatch case.
42+
- [RFC 3425](https://rust-lang.github.io/rfcs/3425-return-position-impl-trait-in-traits.html) — return-position `impl Trait` in traits.
43+
44+
## Crates referenced
45+
46+
- [`tokio`](https://docs.rs/tokio/) — the dominant async runtime.
47+
- [`async-trait`](https://docs.rs/async-trait/) — boxed-future trait macro.
48+
- [`trait-variant`](https://docs.rs/trait-variant/) — generates boxed variants of native async traits.
49+
- [`pin-project`](https://docs.rs/pin-project/) and [`pin-project-lite`](https://docs.rs/pin-project-lite/) — safe `Pin` projection.
50+
- [`bytemuck`](https://docs.rs/bytemuck/) — safe transmutation.
51+
- [`ouroboros`](https://docs.rs/ouroboros/) — self-referential structs without writing `unsafe`.
52+
- [`crossbeam`](https://docs.rs/crossbeam/) — lock-free data structures.
53+
- [`parking_lot`](https://docs.rs/parking_lot/) — faster `Mutex`/`RwLock` than `std`.
54+
- [`embassy`](https://embassy.dev/) — async runtime for embedded.
55+
56+
## Where to go after this book
57+
58+
This book is a survival guide. To go deeper, in roughly this order:
59+
60+
1. Write more code in the patterns from chapter 9 until they are reflexive.
61+
2. Read the source of `tokio`, particularly the `task` and `sync` modules. Surprisingly readable.
62+
3. Read the source of `pin-project` to see what safe pin projection looks like in practice.
63+
4. Read Niko's blog backwards in time, starting from the most recent posts about async.
64+
5. Pick a small `unsafe`-using crate (`bytes`, `parking_lot`, or `crossbeam`) and read its `unsafe` blocks; check the safety comments against your understanding.
65+
6. Run Miri on your own code if you have any. Even if you don't have `unsafe`, Miri will catch some categories of bugs in dependencies.
66+
67+
The material in this book gets internalized by use, not by reading. Write more code. Hit more walls. Each wall, eventually, becomes a door.

0 commit comments

Comments
 (0)