Comments
Anonymous contributor
Published Dec 13, 2023
Contribute to Docs
A comment is a line, or few lines, of text that adds extra explanation to the code to ease readability of the code. Any comment will be ignored and not executed by the compiler. In Rust programming, there are two types of comments:
- Line comments
- Block comments
Line comments
Line comments are single lines of comments. The //
syntax denotes the line of comment which can be placed either before a line of code or at the end of it.
fn main() {//A line comment just before the line of code!println!("Learning about comments in Rust!");println!("First, line comments");//A line comment in the same line of code.}
Block comments
Block comments add various lines of comments. The /*
syntax starts the block of comments, while the */
syntax ends the block.
fn main() {/*A block commentto add various lines.*/println!("Second, the block comments");}
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.