Introduction to Rustlings 🦀❤️
What is Rustlings?
Rustlings is a project designed to help individuals familiarize themselves with reading and writing Rust, a programming language known for its safety and performance. Through this project, participants engage in small exercises that introduce them to Rust's syntax, compiler messages, and fundamental coding principles. It serves as an excellent companion to "The Rust Programming Language" book, often referred to as "the official Rust book," offering a comprehensive learning experience. Additionally, "Rust By Example" provides similar online examples and exercises that complement Rustlings well.
Getting Started
Installing Rust
Before diving into Rustlings, it is essential to have the latest version of Rust installed. This can be accomplished by visiting the Rust installation page, which provides step-by-step instructions tailored to different operating systems. Installing Rust also includes Cargo, Rust's package manager, which simplifies managing project dependencies.
- For Linux users: Ensure
gcc
is installed as a linker. You can install it using eithersudo apt install gcc
for Debian-based systems orsudo dnf install gcc
for Fedora-based systems. - For MacOS users: Xcode and its developer tools are necessary, which can be installed using
xcode-select --install
.
Installing Rustlings
Once Rust is installed, Rustlings can be installed by executing the following command:
cargo install rustlings
If installation issues arise, ensure Rust is up to date by running rustup update
and consider using the --locked
flag if necessary. For persistent issues, users are encouraged to report them to the Rustlings GitHub repository.
Initialization
After successful installation, the Rustlings exercises can be initialized with the following command, creating a rustlings/
directory:
rustlings init
On Linux, if the command is not found, it might be due to ~/.cargo/bin
not being in the PATH
. This can be resolved by manually adding it or by reinstalling Rust via the official method.
Navigate into the initialized directory with:
cd rustlings/
rustlings
Working Environment
Editor Recommendations
While working on Rustlings exercises, using a code editor that supports the rust-analyzer plugin is advisable. Visual Studio Code, complemented by the Rust Analyzer plugin, is a highly recommended choice for newcomers.
Terminal Usage
A modern terminal enhances the Rustlings experience. The standard terminals on Linux and MacOS are suitable, while Windows users may find the Windows Terminal beneficial.
Engaging with Exercises
Exercises are organized by topic within the exercises/<topic>
directory. Each topic includes a README.md
with resources to assist your learning journey. The exercises often contain intentional errors that need correction to compile, and some feature tests that must pass to be considered complete. Look for TODO
comments in the code to identify necessary changes, and use hints by typing h
in watch mode.
Watch Mode
After initializing, Rustlings can be launched with the rustlings
command, activating watch mode. This mode guides users through exercises in a predefined sequence, automatically re-running the current exercise upon file modification. In case of issues detecting file changes, the --manual-run
flag allows manual re-running of exercises.
Interactive Exercise List
In watch mode, users can view an interactive list of exercises by pressing l
. This list provides the status of each exercise and features options to continue different exercises, reset progress, or revisit previous work.
Additional Support
For any assistance or queries during the exercises, the Rustlings GitHub discussions page offers a Question & Answer section to seek help or contribute solutions.
Third-Party and Continuing Exercises
Rustlings also offers third-party exercises from the community, such as the Japanese version, providing diverse learning opportunities. Individuals interested in creating custom or translated Rustlings exercises can refer to the guide for third-party exercises.
Beyond Rustlings
Once completing Rustlings, practitioners are encouraged to apply their newfound Rust knowledge by building their projects, contributing to open-source initiatives, or further contributing to Rustlings itself.
Uninstallation
Should there be a need to uninstall Rustlings, it can be done simply with:
cargo uninstall rustlings
Contributions & Community
The Rustlings project thrives on community contributions and extends gratitude to all its contributors. Those interested in contributing can refer to the CONTRIBUTING.md file for guidelines.
Rustlings offers a comprehensive, interactive path to mastering Rust, pairing exercises with resourceful guides to build a foundational understanding of the language.