Hello, World

The smallest Rust program: fn main() and the println! macro.

Runs in Zerethon IDE · Rust 1.87 Official Rust documentation ↗

A Rust program starts in fn main(). println! is a macro (the ! says so): it checks the format string when the program is compiled.

main.rs
fn main() {
    println!("Hello, World!");
    println!("Sum: {}", 2 + 3);
    let name = "Ada";
    println!("{name}-{}!", "b");
}

Output

Hello, World!
Sum: 5
Ada-b!
  • {} is replaced by the next argument; {name} prints the variable name directly.
  • {:?} prints a value for debugging (vectors, tuples, Option…); print! does not add a newline.
  • Statements end with ;. The last expression of a block without ; is the block's value.