RsRust · Lesson 1 of 8

Hello, World!

Don't worry, the borrow checker is your friend. It's a very aggressive friend who won't let you do anything fun, but it IS your friend. Let's start with something it will definitely approve.

Every Rust program starts with a main() function. Rust files have the .rs extension. The rustc compiler compiles your file to a native binary — no virtual machine, no interpreter.

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

println! is a macro (the ! tells you so). Macros in Rust are more powerful than functions — they can take a variable number of arguments and do compile-time magic. You'll use println! constantly for debugging.

Rust
fn main() {
    // Simple string
    println!("Hello, World!");

    // Formatted output — {} is a placeholder
    let name = "Alice";
    let age = 30;
    println!("Name: {}, Age: {}", name, age);

    // Named placeholders
    println!("{name} is {age} years old.");

    // Debug format — prints almost anything with {:?}
    let numbers = vec![1, 2, 3, 4, 5];
    println!("{:?}", numbers);   // [1, 2, 3, 4, 5]
    println!("{:#?}", numbers);  // pretty-printed

    // eprintln! prints to stderr
    eprintln!("This goes to stderr");
}

To compile and run: rustc hello.rs && ./hello. For any real project, use Cargo — Rust's build system and package manager. cargo new my_project creates a project, cargo run compiles and runs it.

Bash
cargo new hello_world
cd hello_world
cargo run