Rust Comments
Rust supports two comment styles, like other languages (C, Java):
Example
// This is the first comment style
/* This is the second comment style */
/*
* Multi-line comment
* Multi-line comment
* Multi-line comment
*/
Comments for Documentation
In Rust, using // makes everything 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 start of a documentation comment:
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
)
)
;
}
The function add in the program will have an elegant comment, which can be displayed in the IDE:

**Tip:** Cargo has the cargo doc feature, which allows developers to convert documentation comments in a project into HTML-format documentation through this command.