Rust by Example

46 Comments

Comments are a necessary part of any serious program, and most non-serious programs as well.

There are two ways to write comments in Rust, "block" (/**/) and "line" (//). However, the Rust style guide recommends only using the second. There are also "Doc" comments, used for documentation.

fn main() { // This is an example of a line comment // Notice how there are two slashes at the beginning of the line // And that anything written inside these will not 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. It's not used * in Rust very often, and is against the Rust Style Guide. */ }