Learn / Rust / Your first Rust program
Rust, lesson 1 of 5
Your first Rust program
Rust is a programming language built for speed and safety. Browsers, operating systems and security tools use it because it stops whole families of memory bugs before a program ever runs.
Every Rust program starts at a function called main:
fn main() {
println!("Hello, LearnOfficially");
}
fn starts a function. println! prints a line of text. The ! means it is a macro: a shortcut that writes more code for you. Each instruction ends with a semicolon.
Curly brackets {} inside the text are filled with values, in order:
fn main() {
println!("{} has {} lessons", "Rust", 5);
}
On your own computer, you make and run a project with Cargo, Rust's build tool:
cargo new hello # make a new project
cd hello
cargo run # build it and run it