Doc Tests
Tested examples.
What Are Doc Tests?
Doc tests are code examples inside doc comments that Cargo actually compiles and runs. They keep your documentation correct and your examples working.
Code in Doc Comments
Put example code in a fenced code block (three backticks) inside a /// comment, under an # Examples heading. The default language is Rust.
/// Doubles a number.
///
/// # Examples
///
/// let result = my_crate::double(4);
/// assert_eq!(result, 8);
pub fn double(n: i32) -> i32 {
n * 2
}