62

Is there a way I can download the API library docs for Rust or generate them? The only docs I can find in the Rust source are in src/docs.

I'm running the nightly build, so I'm sure there's a way to generate all the docs in the same fashion as the standard docs using rustdoc, I just can't find it!

I'm running Linux, with the nightly build, using this command:

curl -s https://static.rust-lang.org/rustup.sh | sudo sh
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
jonalmeida
  • 1,206
  • 1
  • 9
  • 24

4 Answers4

114

Rustup

If you use rustup, the recommended way to install and update Rust, then the docs may already be installed; the default installation behavior has changed over time. Try running rustup doc to open them in your browser.

If they aren't already installed, you can download the docs by running rustup component add rust-docs.

By default, rustup doc opens the documentation front page, but you can add --std to jump straight to the standard API docs or --book for The Rust Programming Language. You can also use rustup doc std::iter::Iterator to open the documentation of a specific item.

rustup 1.20 learned the concept of profiles. These allow you to default to having docs installed for a toolchain (via the default profile) or not (via the minimal profile).

Standalone Rust Installer

The Rust installer also installs the documentation for the language and for Cargo. On Linux systems, it can be found at /usr/local/share/doc/{rust,cargo}.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • 2
    amazing answer! `rustup` is indeed the tool to have – asgs Apr 14 '19 at 16:32
  • 1
    Rustteam rocks! Amazing how thoughtful Rust language/toolset despite its youth – kirugan Mar 17 '20 at 09:19
  • 1
    Please note, the above does at the moment not work for M1 macs. https://github.com/rust-lang/rustup/issues/2692 – Vange Nov 14 '21 at 12:28
  • @Shepmaster This opens the documentation in a browser. Is there a way to open and navigate within the terminal (say in a remote server situation)? – analytical_prat Sep 04 '22 at 14:39
  • 1
    @analytical_prat to my knowledge, Rust does not produce non-HTML forms of the documentation. I'd suggest looking at using a CLI browser (e.g. [lynx](https://lynx.invisible-island.net/)) or one of the other tools listed below that re-format the Rust documentation. – Shepmaster Sep 12 '22 at 17:27
8

Another way to have the Rust docs (and a few others from languages to frameworks to CLI tools) for offline use is to install Zeal for Linux or Dash for OS X and download Rust's documentation from there.

sargas
  • 5,820
  • 7
  • 50
  • 69
5

If you're running Arch, install rust-docs and navigate to file:///usr/share/doc/rust/html/index.html.

emersion
  • 393
  • 4
  • 10
2

I recommend adding a link to file:///usr/local/share/doc/rust/html/index.html in your browser/desktops bookmarks.

6ft Dan
  • 2,365
  • 1
  • 33
  • 46