English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Rust Basic Tutorial
// Rust's comment styles are the same as other languages (C, Java), and support two types of comments: /* This is the first type of comment */ /* * This is the second type of comment * This is the second type of comment * This is the second type of comment */
In Rust, use // can make the content after it to the first newline become a comment.
Under this rule, three backslashes /// It is still a valid comment start. So Rust can use /// As the beginning of the documentation comment for the explanation document:
///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 a graceful comment and can be displayed in the IDE:
Tip:Cargo has the cargo doc feature, developers can use this command to convert the documentation comments in the project into HTML format documentation.