通过 Cargo 生成文档时如何包含私有模块? [英] How can I include private modules when generating documentation via Cargo?
问题描述
我目前正在使用 Rust 和 Cargo 进行一个项目.它运行良好,但我遇到了一个小问题:为了代码重用,我的大部分项目都在 lib crate 中.在这个板条箱里,很多东西都是私密的.所以当我做 cargo doc
时,我只有公开的、导出的东西的文档......这实际上很棒,因为很容易看到什么是导出的,什么不是.
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...
推荐答案
Rust 1.41
二进制文件的文档默认包括二进制包中的私有项目.
Rust 1.41
Documentation for binaries includes private items from the binary crate by default.
您现在可以使用 cargo doc --document-private-items
你今天可能无法用 Cargo 来做,如果你直接使用 rustdoc 有一个解决方法.
You may not be able to do it with Cargo today, there is a workaround if you use rustdoc directly.
运行 cargo doc -v
并记下它运行的 rustdoc 命令:
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`
然后,在命令中添加--no-defaults --passes strip-hidden --passes collapse-docs --passes unindent-comments
:
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
这篇关于通过 Cargo 生成文档时如何包含私有模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!