Skip to Content
Rust Tutorial

Rust Tutorial

Welcome to our comprehensive Rust tutorial!

What is Rust?

Rust is a systems programming language focused on three goals: speed, safety, and concurrency. It gives you low-level control over memory like C or C++ but without the risk of common bugs like null pointer dereferences, buffer overflows, or data races. This is possible thanks to Rust’s unique ownership system, which is enforced at compile time — no runtime cost, no garbage collector.

Rust is used to build operating systems, game engines, web servers, command-line tools, and WebAssembly applications. Companies like Mozilla, Microsoft, Google, and Amazon use it in production.

Why Learn Rust?

  • Memory safety without a Garbage collector: The compiler catches memory bugs before your code ever runs.
  • Blazing performance: Rust competes with C and C++ in benchmarks.
  • Modern tooling: Cargo (Rust’s build tool and package manager) makes managing projects effortless.
  • Growing ecosystem: Thousands of libraries (called crates) are available on crates.io.
  • Loved by developers: Rust has been the most loved programming language in Stack Overflow’s survey for 8+ years in a row.

What You’ll Learn

  1. Getting Started — install Rust and write your first program

  2. Variables and Mutability — let, mut, constants, and shadowing

  3. Data Types — scalar and compound types

  4. Functions — parameters, return values, and expressions

  5. Comments — documenting your code

  6. Control Flow — if, else if, loops, and loop labels

  7. Ownership — moves, clone, the Copy trait, and memory without a garbage collector

  8. References and Borrowing — &, &mut, the borrow checker, and dangling references

  9. The Slice Type — &str, &[T], range syntax, and borrowing part of a value

  10. Structs — define your own types with named fields, tuple structs, and #[derive(Debug)]

  11. Structs by Example — refactoring a real program into a struct, printing with {:#?}, and the dbg! macro

  12. Enums — define variants, attach data, model alternative states, and use Option

  13. Match and Pattern Matching — match literals and enum data, handle every case, use guards, and choose between match and if let

  14. Concise Control Flow with if let and let...else — handle optional data, borrow enum fields, and use early exits to keep required data in scope

  15. Packages, Crates and Modules — organize Cargo projects, share library code across binaries, and control module paths and privacy

Rust in Practice

For a practical example of a Rust command-line application, read our guide to compressing PDFs offline on Ubuntu with PDFGraph. PDFGraph uses Rust to coordinate QPDF and Ghostscript on your computer. The guide covers building it with Cargo, choosing a compression mode, and checking the result, with links to the source code so you can explore the implementation.

Let’s begin your Rust journey!

Last updated on