Rust comment


Release date:2023-11-07 Update date:2023-11-07 Editor:admin View counts:185

Label:

Rust comment

The annotation methods in Rust are the same as those in other languages (C, Java), supporting two annotation methods:

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

Use in Rust // , you can turn the content that follows to the first newline character into a comment.

Under this rule, three backslashes /// . It’s still the beginning of a legal comment. So Rust can use /// as the beginning of the notes in thedocumentation:

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));
}

Functions in a program add , you will have an elegant comment that can bedisplayed in IDE:

Image0

Tip: Cargo has a cargo doc function, and developers can use this command to convert the notes in the project into HTML format documentation.

Powered by TorCMS (https://github.com/bukun/TorCMS).