Learn Rust – tutorial, cheatsheet & exercises
Rust is a systems programming language that combines maximum speed with memory safety, and it does so without a garbage collector. The ownership system makes this possible: at compile time the compiler checks who owns a value and who may borrow it. Whole classes of bugs such as use-after-free, double free, or data races simply cannot occur.
Rust is used for operating system components, browser engines, WebAssembly, command-line tools (ripgrep, bat), network services, and embedded systems. The learning curve is steep because the compiler is strict, but its error messages are exceptionally helpful, and once your program compiles, many bugs never show up at runtime. The Cargo tool (build, packages, tests) makes everyday work very pleasant.
Hello World in Rust
fn main() {
println!("Hello World!");
}main is the entry point, println! is a macro (recognizable by the !). Run it with cargo run or rustc hallo.rs.
How to get started with Rust
Install Rust via rustup, the official installer and toolchain manager (rustup.rs shows the command for your system; on Windows there is an installer). On a Mac and on Linux, this is all you need in the terminal:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shThen open a new terminal and check that the compiler (rustc) and the build tool (cargo) are available:
rustc --version
cargo --version
rustup update # updates the toolchainYou can compile a single program directly with rustc. For anything serious, use Cargo: cargo new creates a project with Cargo.toml and src/main.rs, and cargo run builds and starts it.
# Single file
rustc hallo.rs
./hallo
# Project with Cargo
cargo new hallo
cd hallo
cargo runcargo check verifies your code quickly without building a binary, and cargo clippy gives style tips.Rust learning path
Hello World, println! & Cargo
Your first Rust program, output macros, and the Cargo workflow.
Variables, Mutability & Types
let, mut, shadowing, and the most important data types.
Conditions & Loops
if as an expression, loop, while, for, and ranges.
Functions & Expressions
Parameters, return values, and the important difference between an expression and a statement.
Ownership: Owning & Moving
The central idea of Rust: every value has exactly one owner.
References & Borrowing
Borrowing values with & and &mut, and the rules of the borrow checker.
Structs & Methods
Custom data types with impl blocks, derive, and constructor functions.
Enums, match & Option
Enums with data, exhaustive pattern matching, and handling “no value”.
Error Handling with Result & ?
Recoverable errors, the ? operator, and custom error types.
Vec, String & HashMap
The most important collections of the standard library and how Rust handles text.
Traits & Generics
Describing shared behavior and writing code for many types.
Iterators & Closures
Functional data processing with no runtime overhead.
Cargo, Modules & Tests
Structuring projects, managing dependencies, and testing code.
At a glance
More about Rust
Test & practice
Interactive quiz, timed exam with certificate, and exercises with an editor: