Rust Comments
Anonymous contributor
Published Dec 13, 2023
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
Learn Rust on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- A quick primer on the fundamentals of the Rust programming language for experienced programmers.
- Intermediate.1 hour