0

I'm writing my first binary crate with Rust and though I have documentation comments for all functions, none of the functions show up in the documentation after running cargo doc --no-deps. The only entry I see in the docs is the name of my crate with a line that starts with //! in my comments.

However, they do show up when I mark modules as public. So in my main.rs, instead of

mod tasks;

if I use

pub mod tasks;

Those modules show up along with their public functions.

I found that I also need to do that for my main function after which it gets listed in the docs. I'm not sure if I should do that.

Am I doing it right?

trent
  • 25,033
  • 7
  • 51
  • 90
myTerminal
  • 1,596
  • 1
  • 14
  • 31
  • In a way it does, but till this point, I've believed that when I'll publish my crate to crates.io, the documentation will automatically show up on docs.rs (I may not wrong). If it does, the elements it'll generate documentation for will be out of my control, right? – myTerminal Jun 13 '20 at 03:05
  • 1
    I have never done any usage with crates.io. But, it looks like you can change this behavior by changing 'rustdocflags' in a cargo configuration file: https://doc.rust-lang.org/cargo/reference/config.html – STF_ZBR Jun 13 '20 at 03:18
  • 1
    You must make the modules public (or publicly re-export the documented items) to make sure that the documentation is generated. Documenting the `main` function is usually not necessary, since it's just the entry point of the application, and the application should be documented in the main module and/or the README. – Aloso Jun 13 '20 at 04:37
  • 1
    docs.rs is a tool for developers to access library documentation. Why would you want your private items to be documented there? – mcarton Jun 13 '20 at 09:05

0 Answers0