The main Function
A free lesson from Swipe Coding · Rust, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Every runnable Rust program needs a function named main — it's the entry point the compiled program starts executing from. You declare it with the fn keyword, followed by the name, a pair of parentheses for its parameters, and a pair of curly braces holding the body.
fn main() {
println!("Hello, world!");
}Rust uses curly braces {} to mark the body of a function, the same style used by C, Java, and JavaScript — unlike Python, which uses indentation alone. Each statement inside the body ends with a semicolon, and the compiler will refuse to build your program if you forget one on a statement that needs it.
A Rust program will fail to compile if it has no fn main() function defined anywhere.
In the program below, where does execution begin?
fn main() {
println!("Hello, world!");
}Hello, Cargo!
10 questions · pass with 60% — just like in the app.
What does cargo new my_project create?
Cargo.toml is the manifest file listing a Rust project's name, version, and dependencies.
Cargo's project manifest file is named ____.
Which file does a new Cargo project put your program code in by default?
Every runnable Rust program must define a function named main.
The function Rust looks for as the starting point of a program is named ____.
How does Rust mark the body of a function like main?
Statements inside a Rust function body end with a semicolon.
What is Cargo?
Rust programs are declared as functions using the ____ keyword.
Keep your streak going in Swipe Coding
Swipe through every level of Rust on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →