Rust Tutorial: Getting Started with Rust
Write your first Rust program, understand the basic structure, and get comfortable with println!.
Your first Rust program
Rust programs start at `fn main()` — the entry point every program needs.
`println!` is a macro (notice the `!`) that prints a line of text to the console.
By the end of this chapter you will understand the shape of every Rust program you will ever write.
What you'll learn in this Rust getting started with rust tutorial
This interactive Rust tutorial has 8 hands-on exercises. Estimated time: 12 minutes.
- Run your first program — Every Rust program starts at `fn main()`. The code inside the curly braces runs when you execute the program.
- Print something different — Change the text inside the quotes to your name and run it.
- Print two lines — Each `println!` prints one line.
- Print a number — `println!` can print numbers too, using `{}` as a placeholder:
- Multiple placeholders — You can use several `{}` in one `println!`:
- Comments in Rust — Comments are notes for humans. Rust ignores them completely.
- Fix the syntax error — This program has a bug. Run it, read the error message, and fix it.
- Write from scratch — The function body is empty. Write a complete Rust program that prints three lines:
Rust Getting Started with Rust concepts covered
- Your first Rust program