Closed
Description
Problem
Many repositories don't have examples written, or the examples are not very long and don't show what the call looks like in context.
Proposed Solution
However, almost any library will have people actually using it. What cargo could do is instead of running rustdoc like this:
rustc --emit=metadata --name=foo crate_a/src/lib.rs
rustc --emit=metadata --name=foo crate_b/src/lib.rs
rustdoc --scrape-examples-target-crate=crate_a --scrape-examples-target-crate=crate_b examples/foo.rs
rustdoc --with-examples=foo.examples crate_a/src/lib.rs
Scrape the examples from the other crates in the workspace as well:
rustc --emit=metadata --name=foo crate_a/src/lib.rs
rustc --emit=metadata --name=foo crate_b/src/lib.rs
rustdoc --scrape-examples-target-crate=crate_a crate_b/src/lib.rs
rustdoc --with-examples=crate_ b.examples crate_a/src/lib.rs
This can be extended to all the dependencies in the whole tree if desired. This does have the drawback that it will take about twice as long to run rustdoc, but since it's opt-in I think the tradeoff is worth it.
Notes
Here's a proof of concept which runs those commands by hand on cargo-deadlinks
: