rustlings
:crab: Small exercises to get you used to reading and writing Rust code!
Top Related Projects
Exercism exercises in Rust.
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.
Rust Programming Fundamentals - one course to rule them all, one course to find them...
Rust explained using easy English
Educational blog posts for Rust beginners
A curated list of Rust code and resources.
Quick Overview
Rustlings is an interactive learning project designed to help beginners learn Rust programming language through small exercises. It provides a series of tasks that gradually introduce Rust concepts, syntax, and best practices, allowing users to practice and gain hands-on experience with the language.
Pros
- Structured learning path with progressive difficulty
- Immediate feedback and hints for each exercise
- Covers a wide range of Rust concepts and features
- Can be run locally or in a web-based environment
Cons
- May not cover advanced Rust topics in depth
- Some exercises might be too challenging for absolute beginners
- Requires a certain level of familiarity with programming concepts
- Limited explanation of theoretical concepts compared to a full course
Getting Started
To get started with Rustlings:
- Install Rust: https://www.rust-lang.org/tools/install
- Clone the repository:
git clone https://github.com/rust-lang/rustlings cd rustlings
- Install Rustlings:
cargo install --force --path .
- Run Rustlings:
rustlings watch
This will start the interactive mode, where you can work through the exercises. Edit the exercise files in your preferred text editor, and Rustlings will automatically check your solutions as you save changes.
To get a hint for the current exercise:
rustlings hint
To verify all exercises:
rustlings verify
Remember to read the instructions carefully for each exercise and refer to the Rust documentation when needed. Happy learning!
Competitor Comparisons
Exercism exercises in Rust.
Pros of Exercism
- Offers a wider variety of exercises covering more Rust concepts
- Provides mentorship and community feedback on solutions
- Includes a web-based interface for easier access and submission
Cons of Exercism
- Less structured learning path compared to Rustlings
- May be overwhelming for absolute beginners due to the large number of exercises
- Requires more setup and familiarity with the Exercism platform
Code Comparison
Rustlings example:
fn main() {
let x = 5;
println!("x has the value {}", x);
}
Exercism example:
pub fn square_of_sum(n: u32) -> u32 {
(1..=n).sum::<u32>().pow(2)
}
Both repositories aim to teach Rust through practical exercises, but they differ in approach. Rustlings focuses on a step-by-step guided learning experience, ideal for beginners. It provides immediate feedback and gradually introduces Rust concepts.
Exercism, on the other hand, offers a more comprehensive set of exercises covering a broader range of topics. It's suitable for learners at various skill levels and provides community support through mentorship.
Rustlings is more tightly integrated with the official Rust documentation and follows a structured curriculum. Exercism allows for more exploration and self-paced learning, with the added benefit of receiving feedback from experienced Rust developers.
Ultimately, the choice between the two depends on the learner's preferences, prior experience, and learning style. Some may find Rustlings more approachable, while others might prefer the depth and variety offered by Exercism.
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.
Pros of Comprehensive Rust
- More comprehensive coverage of Rust concepts, including advanced topics
- Structured as a complete course with slides and exercises
- Regularly updated with new content and improvements
Cons of Comprehensive Rust
- Less hands-on coding compared to Rustlings
- May be overwhelming for absolute beginners
- Requires more time commitment to complete
Code Comparison
Rustlings exercise example:
fn main() {
let x = 5;
println!("x has the value {}", x);
}
Comprehensive Rust exercise example:
fn main() {
let mut x: i32 = 1;
x = 7;
let y: i32 = 4;
println!("x is {} and y is {}", x, y);
}
Summary
Rustlings focuses on hands-on coding exercises, making it ideal for beginners who prefer learning by doing. It offers a gradual introduction to Rust concepts through small, targeted exercises.
Comprehensive Rust provides a more structured learning experience, covering a wider range of topics in greater depth. It's better suited for those who prefer a course-like approach and want to delve into advanced Rust concepts.
Both repositories are valuable resources for learning Rust, with the choice depending on individual learning preferences and goals. Rustlings is better for quick, practical exercises, while Comprehensive Rust offers a more thorough educational experience.
Rust Programming Fundamentals - one course to rule them all, one course to find them...
Pros of ultimate_rust_crash_course
- More structured, course-like approach with video content
- Covers a broader range of Rust concepts in a single package
- Includes more advanced topics like concurrency and async/await
Cons of ultimate_rust_crash_course
- Less frequently updated compared to rustlings
- Fewer exercises overall, potentially less hands-on practice
- May not align as closely with the official Rust Book
Code Comparison
rustlings exercise:
fn main() {
let x = 5;
let y = x;
println!("x = {}, y = {}", x, y);
}
ultimate_rust_crash_course example:
fn main() {
let mut x = 5;
println!("x = {}", x);
x += 1;
println!("x = {}", x);
}
Both repositories provide hands-on Rust learning experiences, but they differ in approach. rustlings offers a larger number of smaller, focused exercises that closely follow the Rust Book. It's regularly updated and maintained by the Rust team. ultimate_rust_crash_course provides a more comprehensive, course-like structure with video content, covering a wider range of topics in a single package. However, it may not be as up-to-date or offer as many individual exercises as rustlings. The choice between the two depends on personal learning preferences and goals.
Rust explained using easy English
Pros of Easy Rust
- More comprehensive text explanations, suitable for beginners
- Covers a wider range of Rust concepts
- Available in multiple languages
Cons of Easy Rust
- Less interactive than Rustlings
- Fewer hands-on coding exercises
- Not officially maintained by the Rust team
Code Comparison
Easy Rust example:
fn main() {
let my_number = 8;
println!("Hello, number {}", my_number);
}
Rustlings example:
fn main() {
let x = 5;
println!("x has the value {}", x);
}
Both repositories aim to teach Rust, but they take different approaches. Rustlings focuses on interactive exercises, while Easy Rust provides more detailed explanations. Rustlings is officially maintained by the Rust team, making it more up-to-date with the latest language features. Easy Rust offers a gentler learning curve for beginners and is available in multiple languages, making it accessible to a wider audience. However, it may not provide as much hands-on practice as Rustlings. The code examples show that both repositories cover similar basic concepts, but Rustlings tends to have more specific, targeted exercises.
Educational blog posts for Rust beginners
Pros of rust-blog
- In-depth, long-form articles covering advanced Rust topics
- Comprehensive explanations with real-world examples
- Regular updates with new content and insights
Cons of rust-blog
- Less interactive than hands-on exercises
- May be overwhelming for absolute beginners
- Lacks structured progression through Rust concepts
Code Comparison
rustlings:
fn main() {
let x = 5;
println!("x has the value {}", x);
}
rust-blog:
fn main() {
let mut x = 5;
x += 1;
println!("x has the value {}", x);
let y = {
let x = 3;
x + 1
};
println!("y has the value {}", y);
}
Summary
Rustlings offers a hands-on, interactive approach to learning Rust through exercises, making it ideal for beginners and those who prefer learning by doing. It provides immediate feedback and a structured learning path.
Rust-blog, on the other hand, offers in-depth articles and explanations, making it better suited for intermediate to advanced Rust developers looking to deepen their understanding of the language. It covers complex topics in detail but may be less engaging for those who prefer a more interactive learning style.
Both resources complement each other well, with Rustlings providing practical exercises and Rust-blog offering comprehensive explanations and advanced insights.
A curated list of Rust code and resources.
Pros of awesome-rust
- Comprehensive resource collection covering a wide range of Rust topics
- Regularly updated with community contributions
- Provides links to libraries, tools, and learning resources
Cons of awesome-rust
- Less hands-on learning compared to interactive exercises
- May be overwhelming for beginners due to the sheer amount of information
- Lacks structured progression for learning Rust concepts
Code comparison
While a direct code comparison isn't relevant for these repositories, here's an example of how they differ in content:
awesome-rust (list of resources):
## Web Programming
* Client
* [cargo-web](https://crates.io/crates/cargo-web) — A Cargo subcommand for the client-side Web
* [stdweb](https://crates.io/crates/stdweb) — A standard library for the client-side Web
rustlings (interactive exercise):
// strings1.rs
fn main() {
let answer = current_favorite_color();
println!("My current favorite color is {}", answer);
}
fn current_favorite_color() -> String {
"blue".to_string()
}
awesome-rust serves as a curated list of Rust resources, while rustlings provides hands-on coding exercises for learning Rust. awesome-rust is better for discovering tools and libraries, while rustlings offers a more structured learning experience for beginners.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Rustlings ð¦â¤ï¸
Greetings and welcome to Rustlings. This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!
It is recommended to do the Rustlings exercises in parallel to reading the official Rust book, the most comprehensive resource for learning Rust ðï¸
Rust By Example is another recommended resource that you might find helpful. It contains code examples and exercises similar to Rustlings, but online.
Getting Started
Installing Rust
Before installing Rustlings, you need to have the latest version of Rust installed. Visit www.rust-lang.org/tools/install for further instructions on installing Rust. This will also install Cargo, Rust's package/project manager.
ð§ If you're on Linux, make sure you've installed
gcc
(for a linker).Deb:
sudo apt install gcc
. Dnf:sudo dnf install gcc
.
ð If you're on MacOS, make sure you've installed Xcode and its developer tools by running
xcode-select --install
.
Installing Rustlings
The following command will download and compile Rustlings:
cargo install rustlings
If the installation fails⦠(click to expand)
- Make sure you have the latest Rust version by running
rustup update
- Try adding the
--locked
flag:cargo install rustlings --locked
- Otherwise, please report the issue
Initialization
After installing Rustlings, run the following command to initialize the rustlings/
directory:
rustlings init
If the command rustlings
can't be found⦠(click to expand)
You are probably using Linux and installed Rust using your package manager.
Cargo installs binaries to the directory ~/.cargo/bin
.
Sadly, package managers often don't add ~/.cargo/bin
to your PATH
environment variable.
The solution is to â¦
- either add
~/.cargo/bin
manually toPATH
- or to uninstall Rust from the package manager and install it using the official way with
rustup
: https://www.rust-lang.org/tools/install
Now, go into the newly initialized directory and launch Rustlings for further instructions on getting started with the exercises:
cd rustlings/
rustlings
Working environment
Editor
Our general recommendation is VS Code with the rust-analyzer plugin. But any editor that supports rust-analyzer should be enough for working on the exercises.
Terminal
While working with Rustlings, please use a modern terminal for the best user experience. The default terminal on Linux and Mac should be sufficient. On Windows, we recommend the Windows Terminal.
Doing exercises
The exercises are sorted by topic and can be found in the subdirectory exercises/<topic>
.
For every topic, there is an additional README.md
file with some resources to get you started on the topic.
We highly recommend that you have a look at them before you start ðï¸
Most exercises contain an error that keeps them from compiling, and it's up to you to fix it! Some exercises contain tests that need to pass for the exercise to be done â
Search for TODO
and todo!()
to find out what you need to change.
Ask for hints by entering h
in the watch mode ð¡
Watch Mode
After initialization, Rustlings can be launched by simply running the command rustlings
.
This will start the watch mode which walks you through the exercises in a predefined order (what we think is best for newcomers).
It will rerun the current exercise automatically every time you change the exercise's file in the exercises/
directory.
If detecting file changes in the exercises/
directory fails⦠(click to expand)
You can add the
--manual-run
flag (rustlings --manual-run
) to manually rerun the current exercise by enteringr
in the watch mode.Please report the issue with some information about your operating system and whether you run Rustlings in a container or virtual machine (e.g. WSL).
Exercise List
In the watch mode (after launching rustlings
), you can enter l
to open the interactive exercise list.
The list allows you toâ¦
- See the status of all exercises (done or pending)
c
: Continue at another exercise (temporarily skip some exercises or go back to a previous one)r
: Reset status and file of an exercise (you need to reload/reopen its file in your editor afterwards)
See the footer of the list for all possible keys.
Continuing On
Once you've completed Rustlings, put your new knowledge to good use! Continue practicing your Rust skills by building your own projects, contributing to Rustlings, or finding other open-source projects to contribute to.
Third-Party Exercises
Do you want to create your own set of Rustlings exercises to focus on some specific topic? Or do you want to translate the original Rustlings exercises? Then follow the link to the guide about third-party exercises!
Uninstalling Rustlings
If you want to remove Rustlings from your system, run the following command:
cargo uninstall rustlings
Contributing
See CONTRIBUTING.md ð
Contributors â¨
Thanks to all the wonderful contributors ð
Top Related Projects
Exercism exercises in Rust.
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.
Rust Programming Fundamentals - one course to rule them all, one course to find them...
Rust explained using easy English
Educational blog posts for Rust beginners
A curated list of Rust code and resources.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot