Rust Comments
Commenting in Rust, like other languages (C, Java), supports two comment styles:
Example
// This is the first comment style
/* This is the second comment style */
/*
* Multi-line comment
* Multi-line comment
* Multi-line comment
*/
/* This is the second comment style */
/*
* Multi-line comment
* Multi-line comment
* Multi-line comment
*/
Documentation comments
In Rust, using//makes the content after it up to the first newline become a comment.
Under this rule, three forward slashes///are still a valid comment start. So Rust can use///as the beginning of documentation comments:
Example
/// Adds one to the number given.
///
/// # Examples
///
/// ```
/// let x = add(1, 2);
///
/// ```
fn add(a: i32, b: i32) -> i32 {
return a + b;
}
fn main() {
println!("{}",add(2,3));
}
///
/// # Examples
///
/// ```
/// let x = add(1, 2);
///
/// ```
fn add(a: i32, b: i32) -> i32 {
return a + b;
}
fn main() {
println!("{}",add(2,3));
}
The function add in the program will then have an elegant comment, and it can be displayed in the IDE:

Tip:Cargo has the cargo doc functionality. Developers can use this command to convert the documentation comments in the project into HTML-format documentation.
Other Extensions