Rust Foundations · 10 min · free with an account

Hello, Rust

Lesson preview · about 30%

A small Rust program gives you the whole development loop: write a function, let the compiler check it, run it, and inspect what appeared on stdout.

Core idea

Execution begins in fn main(). println! is a compile-time-checked macro that writes a formatted line to stdout when the program runs.

Start with the idea

A Rust executable begins in fn main(). The braces enclose the statements that run when the program starts. In the example, name is a string slice, and println!("Hello, {name}!") uses it to build a line of text. The exclamation mark matters: println! is a macro, not an ordinary function call. It expands while the program is compiled, so the compiler can check the format string and its arguments before anything runs. If a placeholder is missing an argument, you see a diagnostic instead of a half-working program.

Follow the diagram from left to right: source code, a successful compile-time check, then terminal output. The compiler’s messages are not the same as your program’s stdout. A clean build can still produce no output if there is no print call; a failed build cannot run this new version at all. When you change the greeting, predict the exact line you expect before tapping Run.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Basics