TIL: Rust documentation redirects

Published Aug 1, 2022

tl;dr: docs.rs/std takes you to Rust std docs, as if it was a crate name!

I’m learning Rust (for the third time now) (and I mean it this time!), and I’m getting deep enough into it that I’m learning shortcuts.

Based on the URL structure for crate documentation (for example, https://docs.rs/axum/latest/axum/), you might wonder whether https://docs.rs/axum takes you anywhere. Spoiler: it does! And it takes you to the longer latest URL, as you’d probably expect.

This is super cool, because that’s a convenient shortcut to the docs for any crate. Typing docs.rs/axum into any good browser’s URL bar takes you straight there.

But some documentation isn’t hosted on docs.rs. In particular, the Rust standard library is on rust-lang.org, and I can never remember the URL structure for that. (It’s https://doc.rust-lang.org/stable/std, by the way).

In the case that brought me to write this, I wanted docs for std::option::Option because I can’t yet cold-recall which of the unwrap variants I want. So I wondered what would happen if I went to docs.rs/std.

And it worked! Those Rustaceans think of everything! 🦀

Like all good dev tools, docs.rs is open-source. There are other special-cased paths, but I’ll leave you to read src/web/routes.rs to figure out what they are 😉