Getting started
First project with Cargo
rust
cargo new hellocd hellocargo runCargo 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}Declare a new variable with let age = ...; then insert it with {age} inside println!.
solution
fn main() { let stable_since = 2015; let current_year = 2026; let age = current_year - stable_since; println!("Rust a {age} ans en {current_year}.");}The compiler infers the i32 type for all three variables. Since Rust 2021, the braces in println! accept a variable name directly.