Rust Basic Syntax


Rust Basic Syntax

In this tutorial, we will learn the basic syntax of Rust language. We will go through the key components of a simple Rust program.

Rust Program

fn main() {
    println!("Hello, World!");
}

Output

Hello, World!

Basic Syntax of a Rust Program

  1. fn main()
    This line defines the main function, which is the entry point of a Rust program. The fn keyword is used to declare a function.
  2. {
    This opening brace marks the beginning of the main function's body.
  3. println!("Hello, World!");
    This line uses the println! macro to print the string "Hello, World!" to the standard output (usually the console).
  4. }
    This closing brace marks the end of the main function's body.

Key Points to Remember

  • All Rust statements must end with a semicolon (;), although it's optional in certain cases.
  • The main function is the entry point of a Rust program.
  • Comments can be added using // for single-line comments or /* ... */ for multi-line comments.
  • Rust is case-sensitive, meaning that println and Println would be considered different.
  • Rust encourages safe concurrent programming and memory safety without sacrificing performance.