AnyCompiler

Your First Rust Program

Every Rust program starts execution in a function called main — this is non-negotiable, unlike JavaScript or Python where code can just run top-to-bottom. println! is a macro (note the !), not a function, which is why you'll see it throughout every lesson here.

Compiling happens first

When you hit run, rustc compiles your entire file into a binary before executing a single line. If there's a type error, a borrow-checker violation, or even just a syntax mistake anywhere, nothing runs at all — you get a compile error instead of output. Rust's compiler has a reputation for being strict, but that strictness is exactly what catches whole categories of bugs before your code ever executes.

Comments

Comments work like most C-family languages: anything after // on a line is ignored completely, and they exist purely so humans reading the code later understand why something is written the way it is.

Run it yourself

Here's a small program with a comment and two println! calls. This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.

// This is a comment - Rust ignores it
fn main() {
    println!("Hello, World!");
    println!("Welcome to Rust.");
}
Output
Hello, World!
Welcome to Rust.

Next: variables and mutability — how Rust makes immutability the default, not an opt-in.

Practice exercise

Add a comment above your code, then print "Learning Rust one step at a time."