How to Use Comments and Documentation Comments in Rust

Use // for private code notes and /// for public API documentation that generates help files.

Use // for single-line comments ignored by the compiler and /// for documentation comments that generate API docs. Place // anywhere to explain code logic, and place /// immediately before items like functions or structs to create public documentation.

// This is a regular comment ignored by the compiler
fn add(a: i32, b: i32) -> i32 {
    a + b
}

/// Adds two numbers and returns the result.
///
/// # Examples
///
/// ```
/// let result = add(2, 2);
/// assert_eq!(result, 4);
/// ```
fn multiply(a: i32, b: i32) -> i32 {
    a * b
}