Rust Syntax
🦀 Rust Syntax
🔹 1. Basic Structure of a Rust Program
Explanation
-
fn→ defines a function -
main()→ entry point of the program -
{ }→ code block -
println!→ macro for printing output -
;→ statement terminator
🔹 2. Comments in Rust
🔹 3. Variables & Mutability
By default, variables are immutable.
🔹 4. Data Types (Basic Syntax)
Rust is statically typed, but it can infer types automatically.
🔹 5. Print Output
🔹 6. If–Else Statement
⚠️ Condition must be boolean (no 1 or 0 like C).
🔹 7. Looping Syntax
▶️ loop (infinite loop)
▶️ while loop
▶️ for loop
🔹 8. Functions
Calling function:
🔹 9. match Statement (Very Powerful)
🔹 10. Statements vs Expressions
🔑 Important Syntax Rules
-
Every statement ends with
; -
No null values (uses
Option) -
Curly braces
{}are mandatory -
No implicit type conversion
-
Compiler errors are very descriptive
