Rust 中的注释分为行注释和文档注释。

行注释:

// Line comments are anything after ‘//’ and extend to the end of the line.

let x = 5; // this is also a line comment.

// If you have a long explanation for something, you can put line comments next
// to each other. Put a space between the // and your comment so that it’s
// more readable.

文档注释用三条斜线,并且注释内容支持 markdown,如:

/// Adds one to the number given.
///
/// # Examples
///
///
/// let five = 5;
///
/// assert_eq!(6, add_one(5));
/// # fn add_one(x: i32) -> i32 {
/// #     x + 1
/// # }
///
fn add_one(x: i32) -> i32 {
    x + 1
}

还有另外一种文档注释://!。通常用来注释包含块(如:crates、modules 或者 functions),经常用在 crates 根文件(lib.rs)和模块根文件(mod.rs)中。

//! # The Rust Standard Library
//!
//! The Rust Standard Library provides the essential runtime
//! functionality for building portable Rust software.

在文档注释中写用法例子非常有用。

参考链接:https://doc.rust-lang.org/stable/book/comments.html