发布于 2015-07-16 14:04:15 | 344 次阅读 | 评论: 0 | 来源: 网络整理
任何程序都有注释,并且Rust确实支持以下几个不同的注释:
// 行注释,到该行的末尾.
/* 块注释,直到结束分隔符. */
/// 下列项目生成文档库.
//! 生成文档库的封闭项.
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);
}