Comments ในภาษา Rust

เราสามารถทำ Comments ในภาษา Rust ได้ง่าย ๆ ด้วยวิธีการต่อไปนี้


  1. ใช้ // ในการ Comment คำสั่งบรรทัดเดียว
  2. ใช้ /// ในการ Comment คำสั่งหลายบรรทัด โดยต้อง Comment ทุกบรรทัดที่ต้องการ
ตัวอย่างการใช้ // ในการ Comment คำสั่งบรรทัดเดียว
// Line comments are anything after '//' and extend to the end of the line.
let x = 5; // this is also a line comment.
// If you have a long explanation for something, you can put line comments next
// to each other. Put a space between the // and your comment so that it's
// more readable.
view raw gistfile1.rs hosted with ❤ by GitHub

ตัวอย่างการใช้ /// ในการ Comment คำสั่งหลายบรรทัด โดยต้อง Comment ทุกบรรทัดที่ต้องการ
/// `hello` is a function that prints a greeting that is personalized based on
/// the name given.
///
/// # Arguments
///
/// * `name` - The name of the person you'd like to greet.
///
/// # Example
///
/// ```rust
/// let name = "Steve";
/// hello(name); // prints "Hello, Steve!"
/// ```
fn hello(name: &str) {
println!("Hello, {}!", name);
}
view raw gistfile1.rs hosted with ❤ by GitHub
ขอบคุณครับ

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

ภาษา Rust คืออะไร