Tip: browse docs locally

After some time with rust I have found that browsing docs locally is more convenient than searching through online. It took me some time to realise hence sharing it here.

cargo doc --open will open all the current crate docs, but also will generate docs for all dependencies. Hence it generates one big solid documentation resource including all libraries used through whole dependencies tree, search allows to quickly find a cross those libs and nav menu on the left allows to pick for specific dependency.

The only thing it does not include is docs from standard library, though those can be easily generated locally via rustup doc

2 Likes

rustup doc --std opens the std api directly instead of the landing page :wink:

4 Likes

cargo doc --document-private-items generates documents for not only public items, but also private ones.
It is very useful for me because I usually document all items and enable #![warn(missing_docs, clippy::missing_docs_in_private_items)] lint.

cargo doc --all-features is also useful, it generates documents with all feature flags enabled.

I added aliases for such useful commands in ~/.cargo/config (linux).

[alias]
d = "doc"
dp = "doc --document-private-items"
da = "doc --all-features"
# Be happy with `cargo dpa`.
dpa = "doc --all-features --document-private-items"
dap = "doc --all-features --document-private-items"
7 Likes

And to pile on to the list of tips, if you don't want to wait for all dependencies documentation to be generated you can use cargo doc -p some-dependency to only generate the documentation for a single crate, but each time you do this for a new crate the resulting documentation pages will allow linking/searching across all crates you have generated so far, so you can slowly build up a collection of documentation for just the crates you care about (until the next cargo clean).

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.