1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! # Showing code examples with code blocks
//!
//! `rustdoc` allows you to define Rust code examples by using triple backticks.
//!
//! ~~~text
//! ```
//! Rust code here
//! ```
//! ~~~
//!
//! It is also possible to define code in other languages.
//! In that case you need to add the code type after the opening backticks:
//!
//! ~~~text
//! ```python
//! Python code here
//! ```
//! ~~~
//!
//! When you run `cargo test`, the Rust code blocks will be compiled and executed.
//! Any errors will be reported.
//! This way your examples are always guaranteed to be up to date!
//!
//! And you get syntax highlighting for free!
//!
//! ```
//! pub struct Ferris {
//! // zero sized type
//! }
//!
//! impl Ferris {
//! pub fn new() -> Self {
//! Self{}
//! }
//!
//! pub fn crab_dance(&self) {
//! println!("Check your borrows, check them all");
//! println!("Fearless concurrency stops the fall");
//! println!("No reference must be left dangling");
//! println!("Interop with C means no mangling");
//! }
//! }
//! ```
//!
//! Let's look at more examples in the [greetings](super::greetings) module
//! and we will also learn about how to write documentation for functions.