This page provides a comprehensive introduction to Rustlings, an educational tool designed to help users learn Rust programming through small, focused exercises. This overview document explains the purpose, architecture, and core components of the Rustlings system.
Rustlings consists of small exercises that help users get comfortable with reading and writing Rust code, including understanding compiler messages. The exercises are designed to be completed alongside reading the official Rust book README.md1-3
The repository contains:
For detailed information on the command-line interface, see Command Line Interface.
Sources: README.md1-14 rustlings-macros/info.toml1-210 src/main.rs168-181
Rustlings follows a modular architecture that separates its functionality into distinct components. The application is centered around the AppState which manages the lifecycle of exercises and their persistence.
The system consists of four primary subsystems:
clap for command parsing src/main.rs37 and crossterm for terminal UI and event handling Cargo.toml50AppState struct src/app_state.rs52-65 and exercise execution through the RunnableExercise trait src/exercise.rs96-200info.toml rustlings-macros/info.toml1-210 and parsed into ExerciseInfo structs src/info_file.rs1-50dev subcommand, supporting exercise creation and verification src/main.rs46Sources: src/main.rs37-46 src/app_state.rs52-65 src/exercise.rs96-200 Cargo.toml50 rustlings-macros/info.toml1-210
The main function in src/main.rs acts as the entry point, routing execution based on parsed CLI arguments.
Rustlings offers two primary interactive modes:
notify crate Cargo.toml51 and automatically re-runs the current exercise. It pauses input while running an exercise to avoid unexpected prompt interactions CHANGELOG.md56s or /) CHANGELOG.md50 and Vim-like keybindings.Sources: src/main.rs101-168 Cargo.toml51 CHANGELOG.md50-56 src/watch.rs1-150
Exercises are the heart of Rustlings. They are organized by topic and defined in rustlings-macros/info.toml rustlings-macros/info.toml1-210
Each exercise is represented by an Exercise struct src/exercise.rs68-78 which tracks its name, directory, path, and completion status. The RunnableExercise trait provides the logic to compile and test exercises using cargo build, cargo test, and cargo clippy src/exercise.rs104-157
| Category | Source Directory | Example Exercise |
|---|---|---|
| Intro | 00_intro | intro1 |
| Variables | 01_variables | variables1 |
| Functions | 02_functions | functions1 |
| Conversions | 23_conversions | conversions2 |
Each exercise file (.rs) typically contains a TODO marker CHANGELOG.md133 and failing tests that the user must fix, such as in exercises/23_conversions/conversions2.rs exercises/23_conversions/conversions2.rs14-20
Sources: src/exercise.rs68-200 rustlings-macros/info.toml1-210 exercises/23_conversions/conversions2.rs14-20 CHANGELOG.md133
Rustlings uses rustlings-macros to embed exercise data directly into the binary at compile time Cargo.toml52
This system ensures:
rustlings init extracts the embedded exercises into the user's current directory src/main.rs45.rustlings-state.txt src/app_state.rs26Sources: Cargo.toml52 src/main.rs45-167 src/app_state.rs26 src/embedded.rs1-50
The project is a Cargo workspace with an MSRV of 1.88 Cargo.toml1-18
unsafe_code and unstable_features Cargo.toml74-76dev command allows developers to check exercise integrity, verify solutions, and create new exercises src/main.rs46dev check ensures all solutions are formatted and all exercises fail when unsolved CHANGELOG.md122-135Refresh this wiki