30 releases

0.1.30 May 21, 2024
0.1.28 Dec 30, 2023
0.1.27 Nov 28, 2023
0.1.25 May 1, 2023
0.1.8 Mar 28, 2022

#125 in Cargo plugins

Download history 19/week @ 2024-02-26 1/week @ 2024-03-04 9/week @ 2024-03-11 56/week @ 2024-04-01 18/week @ 2024-04-15 172/week @ 2024-05-20 14/week @ 2024-06-03 7/week @ 2024-06-10

193 downloads per month

MIT license

494 lines


crates.io Documentation Dependency Status Build Status

A cargo plugin for serving rust and crate doc locally.

$ cargo docs --help
Usage: cargo docs [OPTIONS] [EXTRA_ARGS]...

  [EXTRA_ARGS]...  Passthrough extra args to `cargo doc`

      --host <HOST>                    Set host [env: HOST=] [default:]
  -p, --port <PORT>                    Set port [env: PORT=] [default: 8080]
  -r, --random-port                    Use random port [env: CARGO_DOCS_RANDOM_PORT=true]
  -s, --search <ITEM>                  Search for item
  -d, --dir <DIR>                      Serve directory content [env: DIR=]
  -c, --manifest-path <MANIFEST_PATH>  Crate manifest path [default: Cargo.toml]
  -w, --watch                          Re-generate doc on change [env: CARGO_DOCS_WATCH=]
  -o, --open                           Open in browser [env: CARGO_DOCS_OPEN=true]
  -b, --book                           Serve rust book and std doc instead
  -h, --help                           Print help information
  -V, --version                        Print version information

By default, it will call cargo doc to build crate doc and start a local server.

Add --book option to see rust doc instead.


$ cargo install cargo-docs


Serve crate doc on random port and open in browser

$ cargo docs -ro
[INFO] Serving crate doc on
[INFO] Opening

Same as above plus automatically rebuild and reload on file changes.

$ cargo docs -row
[INFO] Listening for changes...
[INFO] Serving crate doc on
[INFO] Opening

Serve rust docs instead (roughly the same as cargo-book)

$ cargo docs -bro
[INFO] Serving rust doc on
[INFO] Opening

Search for SocketAddr in rust std doc served on random port and open it in browser

$ cargo docs -bros SocketAddr
[INFO] Serving rust doc on
[INFO] Opening

Pro Tips

Passthrough cargo doc options after --

$ cargo docs -- --quiet
[INFO] Running cargo doc --quiet
[INFO] Serving crate doc on

If you are on WSL2, set BROWSER=/mnt/c/Path/To/Your/Browser.exe environment variable to open in desktop browser

$ export BROWSER="/mnt/c/Program Files/Firefox Nightly/firefox.exe"

Tired of typing -o, -ro, -row? Try these environment variables to save you some key strokes.

$ export CARGO_DOCS_OPEN=true
$ export CARGO_DOCS_WATCH=true


~2M SLoC