Reading Rust documentation offline
2020-12-26 | updated 2021-02-13
The book & standard library docs
If you installed Rust using rustup
,
there should be a copy on your local filesystem of the narrative
documentation and the API docs for the standard library, which are
also at https://doc.rust-lang.org.
To open the Rust Programming Language book in your default browser:
rustup doc --book
To browse the stdlib API docs:
rustup doc --std
To look up the docs for a specific item:
rustup doc std::string::String
To open any of these in a different browser, pass the path on the filesystem, e.g.:
w3m $(rustup doc --path --std)
See rustup doc -h
for the flags to view the other
books (the Cargo Book, the Rustonomicon, etc.).
Other crates
To view the API docs for a dependency library locally,
rather than going to https://docs.rs,
you can generate the docs for your project with cargo
doc
. If you don’t pass the --no-deps
flag, the
docs for your dependencies will also get written to
target/doc/{library}/
. E.g.:
echo 'rand = "0.8.3"' >> Cargo.toml
cargo doc --offline
w3m target/doc/rand/index.html