位置:首页 > > Rust注释

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

可参考:

库文档