How can I include private modules when generating documentation via Cargo?

亡梦爱人 提交于 2020-01-21 04:13:05

问题


I'm currently working on a project with Rust and Cargo. It works well, but I encounter a little issue: for code reuse, most of my project is inside a lib crate. In this crate, a lot of things is private. So when I do cargo doc, I just have documentation for public, exported stuff... which is actually great, because it's easy to see what is exported and what is not.

But I have to admit: I miss a complete documentation of the whole project, for development purpose...


回答1:


This can be done by passing arguments to rustdoc, after --, eg.

cargo rustdoc -- \
    --no-defaults \
    --passes strip-hidden \
    --passes collapse-docs \
    --passes unindent-comments \
    --passes strip-priv-imports

Based on @Shepmaster's answer, no need for manual copy-pasting.




回答2:


You may not be able to do it with Cargo today, there is a workaround if you use rustdoc directly.

Run cargo doc -v and make a note of the rustdoc command it runs:

$ cargo doc -v
   Compiling docz v0.0.1 (file:///private/tmp/docz)
     Running `rustdoc src/lib.rs -o /private/tmp/docz/target/doc --crate-name docz -L dependency=/private/tmp/docz/target/debug -L dependency=/private/tmp/docz/target/debug/deps`

Then, add --no-defaults --passes strip-hidden --passes collapse-docs --passes unindent-comments to the command:

rustdoc src/lib.rs -o /private/tmp/docz/target/doc --crate-name docz \
    -L dependency=/private/tmp/docz/target/debug \
    -L dependency=/private/tmp/docz/target/debug/deps \
    --no-defaults \
    --passes strip-hidden --passes collapse-docs --passes unindent-comments



回答3:


This is now simpler, just use:

cargo rustdoc -- --document-private-items



回答4:


Use cargo to document private items:

cargo doc --document-private-items


来源:https://stackoverflow.com/questions/29378113/how-can-i-include-private-modules-when-generating-documentation-via-cargo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!