Rust Exercises

Learn by building.

Learn Rust through interactive exercises that let you practice each concept as you go.

01 / Variables

Variables

Variables let you store a value and give it a name so you can use it in your code.

02 / Numbers

Numbers

Rust has separate types for whole numbers and decimals, and each one has a fixed size.

03 / Chars & Bools

Chars & Bools

A char holds a single character and a bool holds true or false.

04 / Statements & Expressions

Statements & Expressions

Expressions return a value and statements do not. This difference shapes how Rust reads your code.

05 / Functions

Functions

A function takes inputs, runs code, and hands a value back. Return types, diverging functions, and match.

06 / Ownership

Ownership

Every value has exactly one owner. Learn how move, clone, and copy control who holds a value.

07 / Borrowing

Borrowing

Borrowing lets you use a value without taking ownership. Learn references, the borrow checker, and lifetimes.

08 / String vs &str

String vs &str

Rust has two string types. String owns its data and can grow. &str is a borrowed slice used for reading.

09 / Slices

Slices

A slice is a borrowed view into part of a collection. Work with arrays and strings without copying data.

10 / Tuples

Tuples

A tuple groups values of different types. Learn indexing, destructuring, and nested tuples.

11 / Structs

Structs

A struct is a custom type that groups named fields. Learn methods, field shorthand, and struct update syntax.

12 / Enums

Enums

An enum represents one of several named variants. Learn how to store data inside variants and model state.

13 / Option

Option

Option is how Rust handles values that might not exist. Use Some and None instead of null.