Post

Comments in Rust

Overview of comments in the Rust programming language.

Comments in Rust

INFO

This short article provides a brief overview of comments (non-doc comments) in Rust. A detailed explanation of doc comments, which are used for generating documentation, will be covered in a separate article.

DOCUMENTATION

Comments in Rust are similar to those found in C, C++, and Java. Single-line comments start with //, and multi-line comments are enclosed between /* and */.

Single-Line Comments

1
2
3
4
// This is a single-line comment
fn main() {
    println!("Hello, World!"); // This is another single-line comment
}

Multi-Line Comments

1
2
3
4
5
/* This is a multi-line comment
   It can span multiple lines */
fn main() {
    println!("Hello, World!");
}
This post is licensed under CC BY 4.0 by the author.