1Rustdoc will automatically scrape examples of documented items from a project's source code. These examples will be included within the generated documentation for that item. For example, if your library contains a public function: 2 3```rust 4// src/lib.rs 5pub fn a_func() {} 6``` 7 8And you have an example calling this function: 9 10```rust 11// examples/ex.rs 12fn main() { 13 a_crate::a_func(); 14} 15``` 16 17Then this code snippet will be included in the documentation for `a_func`. 18 19 20## How to read scraped examples 21 22Scraped examples are shown as blocks of code from a given file. The relevant item will be highlighted. If the file is larger than a couple lines, only a small window will be shown which you can expand by clicking ↕ in the top-right. If a file contains multiple instances of an item, you can use the ≺ and ≻ buttons to toggle through each instance. 23 24If there is more than one file that contains examples, then you should click "More examples" to see these examples. 25 26 27## How Rustdoc scrapes examples 28 29When you run `cargo doc -Zunstable-options -Zrustdoc-scrape-examples`, Rustdoc will analyze all the documented crates for uses of documented items. Then Rustdoc will include the source code of these instances in the generated documentation. 30 31Rustdoc has a few techniques to ensure this doesn't overwhelm documentation readers, and that it doesn't blow up the page size: 32 331. For a given item, a maximum of 5 examples are included in the page. The remaining examples are just links to source code. 342. Only one example is shown by default, and the remaining examples are hidden behind a toggle. 353. For a given file that contains examples, only the item containing the examples will be included in the generated documentation. 36