Should rustdoc include cargo examples?

I am referring to the examples that come from examples/ directory of a crate in the default configuration, or whatever is specified as [[example]] in the Cargo.toml.

When I use a crate dependency, I will generally look at its documentation on I am not in the habit of going into the source repository, especially since the page usually includes its own copy of the source code. However I realized today that the rustdocs do not include examples so the source repository is the only place to see the examples. Anything that a crate author puts in [[example]] instead of [[bin]] or [[test]] is probably intended to serve as documentation in some way, so would it make sense for rustdoc to package up the source code of all examples and include them in the docs?

1 Like

This is already implemented in rustdoc, but not yet stabilised.

You can use it with the following command:

cargo doc -Zunstable-options -Zrustdoc-scrape-examples

just want to mention, it is supported on too! this is a really useful documenting feature. I hope more crates will utilize this feature. to enable this feature on, you add the following metadata section to your Cargo.toml manifest:

cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]

here's an example how it looks on


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.