Comments - Rust by Example
Comments - Rust by Example
2023 12:48
Comments
Any program requires comments, and Rust supports a few different varieties:
1 fn main() {
2 // This is an example of a line comment.
3 // There are two slashes at the beginning of the line.
4 // And nothing written after these will be read by the compiler.
5
6 // println!("Hello, world!");
7
8 // Run it. See? Now try deleting the two slashes, and run it again.
9
10 /*
11 * This is another type of comment, a block comment. In general,
12 * line comments are the recommended comment style. But block comments
13 * are extremely useful for temporarily disabling chunks of code.
14 * /* Block comments can be /* nested, */ */ so it takes only a few
15 * keystrokes to comment out everything in this main() function.
16 * /*/*/* Try it yourself! */*/*/
17 */
18
19 /*
20 Note: The previous column of `*` was entirely for style. There's
21 no actual need for it.
22 */
23
24 // You can manipulate expressions more easily with block comments
25 // than with line comments. Try deleting the comment delimiters
26 // to change the result:
27 let x = 5 + /* 90 + */ 5;
28 println!("Is `x` 10 or 100? x = {}", x);
29 }
See also:
https://doc.rust-lang.org/rust-by-example/hello/comment.html Stránka 1 ze 2
Comments - Rust By Example 09.10.2023 12:48
Library documentation
https://doc.rust-lang.org/rust-by-example/hello/comment.html Stránka 2 ze 2