注释
任何程序都需要注释,Rust 支持几种不同的注释类型
- 普通注释,编译器会忽略它们
// 行注释,一直持续到行尾。
/* 块注释,一直持续到结束分隔符。 */
- 文档注释,会被解析成 HTML 库 文档
/// 为以下项目生成库文档。
//! 为封闭项目生成库文档。
fn main() { // This is an example of a line comment. // There are two slashes at the beginning of the line. // And nothing written after 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, a block comment. In general, * line comments are the recommended comment style. But block comments * are extremely useful for temporarily disabling chunks of code. * /* Block comments can be /* nested, */ */ so it takes only a few * keystrokes to comment out everything in this main() function. * /*/*/* Try it yourself! */*/*/ */ /* Note: The previous column of `*` was entirely for style. There's no actual need for it. */ // You can manipulate expressions more easily with block comments // than with line comments. Try deleting the comment delimiters // to change the result: let x = 5 + /* 90 + */ 5; println!("Is `x` 10 or 100? x = {}", x); }