Offline viewing of crate documentation with rustup/cargo

I’ve been wondering if rustup doc or cargo should be extended with a command to build and open documentation for a crate installed as an dependency. My current approach to do that is to enter the .cargo directory, look for the crate + version and invoke cargo doc --open.

I think it would be a helpful extension to just invoke something like rustup doc CRATE [--version VERSION] as we already use rustup doc to view the std documenation/book offline. This shouldn’t be too hard to implement and I’d be willing to do this if there’s interest from the community. Any opinions on this? Or is there already a different approach (I looked but couldn’t find one)?

If it’s a dependency in your current Cargo.toml (or a dependency of a dependency etc.) you should be able to open its docs with cargo doc --open --package foo. A normal cargo doc will actually generate the documentation for your entire dependency tree, by passing --package foo you can limit it to the foo crate in case you have a lot of dependencies.


Thanks for the info. This handles the case where the library is already a depenency of a crate, which is probably the prevalent use case. I’m not sure how often you’d want to view documentation of a crate offline if it is not a dependency. Maybe to compare the documentation of different versions?

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