- Mastering Rust
- Rahul Sharma Vesa Kaihlavirta
- 143字
- 2021-07-02 13:35:26
Generating and viewing documentation
To generate documentation, we can use the cargo doc command in our project directory. It generates docs in the target/doc/ directory with a bunch of HTML files and predefined stylesheets. By default, it generates docs for a crate's dependencies too. We can tell Cargo to ignore generating docs for dependencies by running cargo doc --no-deps.
To view the documentation, one can spawn a HTTP server by navigating inside the target/doc directory. Python's simple HTTP server can come in handy here. However, there's a better way to do this! Passing the --open option to cargo doc will open the documentation page directly in your default browser.
cargo doc can be combined with cargo watch to get a seamless experience in writing documentation and getting live feedback on the generated page for any documentation changes you do on your project.