Feature request: rustdoc → find all .rs files in the project

Hello, I'm the author of vim-dooku and dooku.nvim, a plugin for neovim.

When implementing multi-os support for rustdoc, I have the issue of not having a way to pass all the .rs files of the project to rustdoc.

Which forces me to use "cargo doc", which has this capability. But then I don't have most configuration options available on rustdoc, and I'm forced to create the docs on target/doc.

Please, implement a rustdoc argument to detect all .rs files from the current directory, recursively.

There’s cargo rustdoc to run rustdoc against the current crate with a set of extra arguments. Rustdoc cannot generally be run against just the .rs files from a cargo project, it relies on other metadata that cargo passes, like --extern flags. (And rustdoc doesn’t run against individual files, it runs a crate at a time just like rustc, which for a cargo project is generally just the root src/lib.rs).

Yes, by reading the official docs before posting here I got that impression.

I understand "cargo rustdoc" is the prefered way to generate documentation. Specially if as you say, cargo metadata is necessary to generate correct project documentation. And also considering with rustdoc we would have to assume the user project structure, which we don't know.

What I don't get is why do you have more configuration options in rustdoc (like enabling dark mode) while you don't have those in "cargo rustdoc". Are there planned to be added to "cargo doc" in the future?

All rustdoc flags can be used with cargo rustdoc if you want them to apply to just the current project, like cargo rustdoc -- --document-private-items, they can also be used with cargo doc if you want them to apply to all dependencies too RUSTDOCFLAGS=--document-private-items cargo doc.

1 Like

Thank you so much for your answer nemo157.

Running cargo rustdoc -- --document-private-items worked fine; thank you for documenting how to do it.

I see what the command rustdoc actually runs is:

rustdoc --edition=2021 --crate-type bin --crate-name rust main.rs -o /home/zeioth/dooku_tests/rust/target/doc --error
-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=154 --document-private-items --no-run --document-private-items '
-Arustdoc::private-intra-doc-links' -C metadata=050b21729e6b2bc8 -L dependency=/home/zeioth/dooku_tests/rust/target/debug/deps --crate-version 0.1.0`

I see one can can pass rustdoc parameters like:

cargo rustdoc -- --document-private-items --default-theme=dark

but some of them will fail like

cargo rustdoc -- --document-private-items --output=mydir

Running the full command pasted above manually, gives a bit more insight: "cannot use both 'out-dir' and 'output' at once".

So it's not perfect, some parameters seem to conflict, but at least users can now use rustdoc parameters. Thank you!!

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