Your First Program: Hello World

Updated

October 31, 2026

Your First Program: Hello World

Let’s begin with the canonical starting point: a minimal standalone Rust source file.

Direct Compilation with rustc

Create a file named main.rs:

// main.rs
fn main() {
    println!("Hello, world!");
}

Compile and run directly using rustc:

rustc main.rs
./main

Output:

Hello, world!

Deconstructing the Program

  • fn main() { ... }: The main function is the entry point of every executable Rust program. It takes no arguments and returns unit ().
  • println!(...): In Rust, names ending in an exclamation mark ! invoke macros rather than standard functions. println! parses format strings at compile time to ensure type safety.