Rust注释

任何程序都有注释,并且Rust确实支持以下几个不同的注释:

  • 规则注释其由编译器忽略:
    • // 行注释,到该行的末尾.
    • /* 块注释,直到结束分隔符. */
  • 这会被解析成HTML库文档注释
    • /// 下列项目生成文档库.
    • //! 生成文档库的封闭项.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    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);
    }


联系我们

邮箱 626512443@qq.com
电话 18611320371(微信)
QQ群 235681453

Copyright © 2015-2024

备案号:京ICP备15003423号-3