The annotation methods in Rust are the same as those in other languages (C, Java), supporting two annotation methods: Use in Rust Under this rule, three backslashes Functions in a program Tip: Cargo has a cargo doc function, and developers can use this command to convert the notes in the project into HTML format documentation. 7.7.1. Example #
//This is the first annotation method
/*This is the second annotation method*/
/*
*Multiple line comments
*Multiple line comments
*Multiple line comments
*/
Comments used to describe the document #
//
, you can turn the content that follows to the first newline character into a comment.
///
. It’s still the beginning of a legal comment. So Rust can use
///
as the beginning of the notes in thedocumentation: 7.7.2. 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));
}
add
, you will have an elegant comment that can bedisplayed in IDE: