Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
687 views
in Technique[技术] by (71.8m points)

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

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Rust 1.41

Documentation for binaries includes private items from the binary crate by default.

Rust 1.29

You can now use cargo doc --document-private-items

Previous versions

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...