Skip to main content

Rust examples

Every example is a complete program. Read the explanation, then open it in the editor and break it on purpose — that is where the learning happens.

42 examples

Basics

Values, types, control flow and the shape of a Rust program.

Memory

Ownership, borrowing, slices and lifetimes.

Data

Structs, enums, collections and generics.

Behaviour

Closures, iterators and traits.

Robustness

Option, Result, custom errors, panics and tests.

Systems

Smart pointers, modules and threads.