Line comments
// This is a line comment
Multi-line comments are allowed but rarely used
/* This is not
very common */
Doc comments
/// This is mainly used to document functionality.
Markdown comments: Heading
//! # Main heading
Markdown comments: Code
//! ```
//! fn main()
//! ```
Create documents
$ cargo doc
Example
use std::io;
/// Crate comment.
/// What is this module trying to achieve.
fn main() {
//! # Main function
//!
//! ```
//! fn main()
//! ```
//!
//! Reads user input and prints it to the console.
//!
let mut input = String::new();
// print a message to the user
println!("Say something");
/* check response and
act accordingly */
match io::stdin().read_line(&mut input) {
Ok(_) => {
println!("You said {}", input);
},
Err(e) => {
println!("Something went wrong {}", e);
}
}
}