- Explain where Rust came from and where it is used
- Compare three approaches to memory management: manual, garbage collection and ownership
- Install Rust with rustup and use
cargo new,cargo runandcargo build - Print text and variables with the
println!macro
Imagine a language that runs as fast as C++ but will not let you make memory mistakes: the compiler itself finds the bug before the program ever crashes. Engineers at Microsoft and Google have reported that about 70% of the serious security vulnerabilities in their products come from memory errors. Rust was created to solve exactly this problem, and today it is one of the most loved programming languages.
Rust in a nutshell
Rust is a systems programming language: code is compiled straight to machine code, with no virtual machine or interpreter. It makes three main promises: speed (on the level of C and C++), memory safety (dangling pointers, double frees and data races are caught at compile time) and productivity (the Cargo tool, clear error messages and a strong type system).
- 2006A personal project
Mozilla employee Graydon Hoare starts working on Rust as a personal project.
- 2009Mozilla steps in
Mozilla begins to sponsor the project officially and develops it for browser technology.
- 2015Rust 1.0
The first stable version is released in May. Since then, a new version has come out every 6 weeks.
- 2021The Rust Foundation
AWS, Google, Huawei, Microsoft and Mozilla found an independent foundation to support the language.
- 2022Inside the Linux kernel
Linux 6.1 adds initial support for writing drivers in Rust.
Where is Rust used?
- Operating systems — Linux kernel drivers, some Windows components and new parts of Android.
- Browsers — several parts of Firefox, for example the Stylo engine that computes CSS styles.
- WebAssembly — Rust code compiles to WebAssembly and runs in the browser at nearly native speed.
- Command-line tools — fast tools such as
ripgrep,fdandbat; the search in the VS Code editor is powered byripgrep. - Servers and the cloud — AWS Firecracker virtual machines and high-load services at Cloudflare and Discord.
Memory safety without a garbage collector
Every program allocates memory while it runs and must give it back later. In C and C++ the programmer does this by hand, and a mistake crashes the program or opens a security hole. In Java, Python and Go a garbage collector cleans up unused memory in the background, but this costs extra memory and time. Rust chose a third way: ownership rules. The compiler tracks who owns each value and frees the memory itself at exactly the right moment.
| Approach | Languages | Strength | Weakness |
|---|---|---|---|
| Manual management | C, C++ | maximum speed and control | leaks, dangling pointers |
| Garbage collector | Java, C#, Python, Go | convenient and safe | pauses, extra memory |
| Ownership and the borrow checker | Rust | both speed and safety | harder to learn at first |
Installing with rustup
- 1Get the installer
On Windows, download
rustup-init.exefromrustup.rsand run it. On macOS and Linux, run thecurlcommand shown below in a terminal. - 2C++ build tools on Windows
On Windows, Rust needs Microsoft's Visual Studio C++ Build Tools. The installer offers to set them up — accept the default options.
- 3Check the installation
Open a new terminal and type
rustc --versionandcargo --version. Both should print a version number. - 4Update from time to time
The
rustup updatecommand upgrades Rust to the latest stable version.
# macOS / Linux
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# any OS: check the tools
rustc --version
cargo --versionrustc), Cargo, the rustfmt formatter, the clippy linter and the standard library documentation.Your first project with Cargo
Cargo is Rust's official build tool and package manager: it creates projects, compiles code, runs programs, runs tests and downloads libraries. The cargo new command creates a new project:
cargo new hello
cd hello
cargo runhello/
├── Cargo.toml
├── .gitignore
└── src/
└── main.rsCargo.toml holds the project's name, version and dependencies, and the code lives in src/main.rs. Cargo also creates a git repository.[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[dependencies]edition is the language edition (2015, 2018, 2021, 2024). New projects get the latest one; the code in this course works in both the 2021 and 2024 editions.fn main() {
println!("Hello, world!");
}Hello, world!
fn main()is the entry point; the program starts running here.println!is not a function but a macro — in Rust, macros are recognised by the!at the end of the name.- Text goes in double quotes and the statement ends with
;. Indentation uses 4 spaces.
$ cargo run
Compiling hello v0.1.0 (/home/aysel/hello)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.61s
Running `target/debug/hello`
Hello, world!cargo run first compiles the code (into the target/debug folder) and then starts the program. The timing will differ on every computer.Printing variables
Inside the println! text, {} is a placeholder: it is replaced by the value given after the comma. You can also put a variable's name straight into the braces: {name}. Variables are created with the let keyword — more on that in the next lesson.
fn main() {
let name = "Aysel";
let year = 2015;
println!("Hello, {name}!");
println!("Rust 1.0 was released in {}.", year);
println!("{} + {} = {}", 2, 3, 2 + 3);
}Hello, Aysel! Rust 1.0 was released in 2015. 2 + 3 = 5
| Command | What it does |
|---|---|
cargo new name | creates a new project |
cargo run | compiles and runs |
cargo build | builds into target/debug |
cargo build --release | builds an optimised version into target/release |
cargo check | only checks for errors without producing a file — the fastest |
cargo fmt | formats the code in the official style |
cargo clippy | analyses the code and gives advice |
fn main() {
let name = 'Aysel';
println("Hello, {name}!");
}fn main() {
let name = "Aysel";
println!("Hello, {name}!");
}char); text goes in double quotes. Calling println without the ! gives error E0423, and the compiler suggests writing println!.Key points
- Rust is a compiled systems language that combines speed, memory safety and productivity.
- Rust has no garbage collector: memory is managed by ownership rules that the compiler checks.
- rustup installs and updates Rust; Cargo creates, builds and runs projects and downloads libraries.
println!is a macro; the placeholders{}or{name}insert values into the text.- When speed matters, build an optimised version with
cargo build --release.
Check yourself
10 questions. Every correct answer earns XP.