A Rust program runs from main. This example binds a name, builds a greeting with format!, and prints it.

Program

Play the program to watch name flow into greeting, then print.

hello.rs
Replay: real traced execution (multi-file project)
fn main() {
    let name = "Ada";
    let greeting = format!("Hello, {name}!");
    println!("{greeting}");
}
  1. name ← "Ada", greeting ← "Hello, Ada!"

    1fn main() {2    let nam→ "Ada"e = "Ada";3    let greetin→ "Hello, Ada!"g = format!("Hello, {name}!");4    println!("{greeting}");5}
    outputHello, Ada!

Follow the Greeting

  1. name starts as "Ada".
  2. format!("Hello, {name}!") puts Ada into the greeting text.
  3. greeting becomes Hello, Ada!.
  4. println! prints that greeting on one line. | value name | value | | --- | --- | | name | Ada | | greeting | Hello, Ada! | | printed output | Hello, Ada! |
let binding `let` binds a value to an immutable name.
format! `format!` builds a `String` from a template and values.
println! `println!` writes a line to standard output.

Exercise: hello.rs

Reproduce the output Hello, Ada!, then change name and predict the exact greeting before running it.