Rust註釋

Rust註釋

任何程序都有註釋,並且Rust確實支持以下幾個不同的註釋:

  • 規則註釋其由編譯器忽略:
    • // 行註釋,到該行的末尾.
    • /* 塊註釋,直到結束分隔符. */
  • 這會被解析成HTML庫文檔註釋:文檔:
    • /// 下列項目生成文檔庫.
    • //! 生成文檔庫的封閉項.

fn main() {
// This is an example of a line comment
// Notice how there are two slashes at the beginning of the line
// And that nothing written inside these will be read by the compiler

// println!("Hello, world!");

// Run it. See? Now try deleting the two slashes, and run it again.

/\* 
 \* This is another type of comment, the block comment. In general,
 \* the line comment is the recommended comment style however the
 \* block comment is extremely useful for debugging
 \*/

 /\*
 Note, the previous column of \`\*\` was entirely for style. There's
 no actual need for it.
 \*/

 // Observe how block comments allow easy expression manipulation
 // which line comments do not. Deleting the comment deliminators
 // will change the result:
 let x = 5 + /\* 90 + \*/ 5;
 println!("Is \`x\` 10 or 100? x = {}", x);

}

可參考:

庫文檔