Press the orange Run button below. That’s it. You just compiled and ran a Rust program.
fn main() {
println!("Hello, world!");
}
Expected output
Hello, world!
No installing, no setup. The code ran on the official Rust Playground and came back with what it printed. Every code box in this course works the same way, and you can edit any of them. Try changing world to your own name and press Run again.
What is Rust, in one minute
Rust is a programming language for building fast, reliable software. It is used for command-line tools, web servers, game engines, browsers and even operating systems. Parts of Firefox, Android, Windows and the Linux kernel are written in Rust.
Rust has a reputation for being hard. Here is the honest version: Rust is strict, not hard. It checks your program very carefully before it runs, and when something is wrong it tells you exactly what and where, often with the fix. That strictness is why Rust programs crash so rarely. In this course we treat the compiler as a patient teacher, not an enemy.

That picture is the whole story of every program in this course:
- You write source code in a file, by convention
main.rs. - The compiler (
rustc) reads it, checks it, and either builds a program or explains what to fix. - The program runs and prints its output.
Every line of Hello, world
Here is the program again, taken apart.

fn main()declares a function calledmain.fnis short for function. Every Rust program starts running atmain.{ }The curly braces hold the function’s body: the steps to run, in order.println!prints a line of text. The!matters: it marks a macro, a special kind of command that writes code for you. You will meet more macros later; for now, remember that printing isprintln!with the!."Hello, world!"is a string, text in double quotes.;The semicolon ends the step, like a full stop ends a sentence.
Predict, then check
Learning sticks best when you guess first. Before you look, what will this print?
Predict the output
What will this program print?
fn main() {
println!("Rust is fun!");
println!("Let's begin.");
println!("Ready?");
}
Show the real output
Rust is fun! Let's begin. Ready?
Each println! prints its text and then moves to a new line, so the three lines appear one after another, top to bottom, in the order they are written.
Your turn: print three lines about you
Change the program so it prints three lines: your name, where you are, and one thing you want to build with Rust. Press Run to check. There is no wrong answer here; if it runs, you did it.
fn main() {
println!("My name is Sam.");
println!("I live in Chennai.");
println!("I want to build a game.");
}
Expected output
My name is Sam. I live in Chennai. I want to build a game.
Fix the bug
Mistakes are part of programming, and Rust’s error messages are some of the friendliest around. This program has one small mistake. Read the compiler’s message, then fix the code and press Run until it works.
Fix the bug
This program does not compile. Read the error, change the code, and run it until it works.
fn main() {
println("Hello, Rust!");
}
What the compiler says
error[E0423]: cannot find function `println` in this scope
--> src/main.rs:2:5
|
2 | println("Hello, Rust!");
| ^^^^^^^ not found in this scope
|
= note: a macro named `println` exists in another namespace
help: use `!` to invoke the macro
|
2 | println!("Hello, Rust!");
| +
Hint
The compiler cannot find a function called println, but it notices a macro with that name. Read its "help" line: what does a macro name need at the end?
Show the fix
fn main() {
println!("Hello, Rust!");
}
It prints
Hello, Rust!
Notice what the compiler did there: it pointed at the exact spot, named the problem, and suggested the fix. Get used to reading these messages top to bottom. They are the fastest way to learn.
Quick check
Quick check
-
Rust always starts at fn main(), wherever it appears in the file.
-
The ! tells you (and the compiler) that println! is a macro. Without it, Rust looks for a function called println and cannot find one.
-
Steps (statements) end with ;. A new line on its own does not end a step in Rust.
Recap
- A Rust program starts at
fn main(), and its steps go inside{ }. println!("...")prints a line. The!means it is a macro.- The compiler checks your code before it runs. When it complains, read the message: it usually tells you the fix.
Next: printing is more useful when it can show values, not just fixed text. In the next lesson you will make println! fill in blanks.
Leave a Reply