rsRustPrimer
< Back to module

Getting started

First project with Cargo

rust
cargo new hello
cd hello
cargo run
Creates a binary project, builds it, then runs it: it prints "Hello, world!".

Cargo generated two files. Cargo.toml describes the project (name, version, Rust edition, dependencies). src/main.rs holds the program entry point: the main function.

rust
fn main() {
let language = "Rust";
let year = 2015;
println!("Hello, {language}! Stable since {year}.");
}
println! is a macro (the ! gives it away). Braces insert a variable into the text.

Everyday commands: cargo check verifies the code compiles without producing a binary (very fast), cargo build --release produces an optimized binary in target/release, cargo fmt formats the code and cargo clippy suggests idiomatic improvements.

Your turn

Change this program so it prints "Rust is 11 years old in 2026." by computing the age from the two variables.

src/main.rs
fn main() {
let stable_since = 2015;
let current_year = 2026;
// calcule l'âge puis affiche la phrase
}