How Doctests Work
summary
Doctests run as compiled crates, which makes them slow, so a merged doctest runner is built that compiles one binary and then uses libtest to spawn each example in its own process, cutting compile time — 3× faster on std, 4× on core, crates 4–8× and one crate showed ~30×. It uses a small nightly-only helper backported to stable (expected 1.84.1), but limitations remain: can't run compile-fail or show-output in merged mode and private/non-public APIs are still untestable.
AI-written summary · about
chapters (13)
- 0:00Introduction and speaker intro
- 1:08What are doctests
- 2:36Doctest attributes and options
- 5:46Advanced doctest features
- 7:12How doctests work internally
- 10:06Limitations of doctests
- 11:31Faster doctests in Rust 2024
- 13:18Merged doctests explained
- 16:31Merged doctests limitations
- 18:40Nightly features workaround
- 19:45Forcing standalone doctests
- 20:29Future of doctests
- 22:16Q&A and closing
