How to Add Examples to Rust Documentation

Add Rust code examples to documentation by creating listing directories and using the rustdoc_include directive in markdown files.

Add examples to Rust documentation by creating a new listing directory in listings, adding your code, and using the {{#rustdoc_include}} directive in your markdown file.

// In your markdown file (e.g., src/ch01-00-getting-started.md)
{{#rustdoc_include listings/ch01-01-installation/src/main.rs}}

To include only a specific section, wrap the code in // ANCHOR: tag and // ANCHOR_END: tag comments in the source file, then reference the tag in the directive:

{{#rustdoc_include listings/ch01-01-installation/src/main.rs:main_function}}