What Is This Course About?

Practice Rust in a fun way by solving these twenty-four brain-teasing puzzles.

Rust as a programming language

Rust is a very consistent language. The Rust Core team has worked hard to ensure that Rust does what you ask and doesn’t surprise users by performing additional tasks without the programmer’s knowledge. Rust’s toolset—particularly Clippy—checks programming for common mistakes and often suggests improvements.

The Rust language has a few quirks. Sometimes they creep into the cracks between systems, and sometimes they’re a conscientious design choice to avoid doing something unintended. In this course, you’ll review a series of self-contained Rust programs that explore these quirks. Each program, known as a brain teaser, teaches an aspect of Rust that is designed to surprise you. As you read each brain teaser, try to predict the program’s output. The possible answers are illustrated below:

After each brain teaser, there’s an explanation of why the program produces the result that it does as well as a discussion about how similar issues might affect the code you write in your programs.

To get the most out of this course, try analyzing the code yourself before moving to the next lesson. Taking these steps will help reinforce what you’re learning.

By understanding these quirks, you can become a better Rust programmer, and, hopefully, avoid these pitfalls in your own projects.

The intended audience

Although there are a lot of code executables and terminals inside this course, you need a working installation of Rust and some familiarity with making and running Rust applications before getting started. These brain teasers are targeted at beginner and intermediate-level developers.


Note: If you are new to Rust, The Rust Language by Steve Klabnik and Carol Nichols or Hands-on Rust: Effective Learning through 2D Game Development and Play are a good place to start.

If you are completely new to Rust, you can learn the basics in the course Learn Rust from Scratch.

What to expect

The quizzes and code are as short as possible and focused on displaying each brain teaser’s minimal reproducible example. The examples are contained within a Rust workspace. To execute each sample, change to the example’s directory in your terminal and type cargo run.

Some brain teasers require additional library support. In these cases, the Cargo.toml file is displayed next to the example’s source code.

This course outlines some of Rust’s quirks and, sometimes, programming in general. Despite its oddities, Rust is a fantastic language. Exposing these quirks isn’t meant to serve as criticism of the language. Instead, this course is designed to help you discover why things are done the way they are. Soon, those oddities may seem less quirky and more deliberate.

Throughout this course, keep an open mind and approach each brain teaser like a crime scene investigator. All of the clues are present. Once you understand the discussion behind each brain teaser, you’ll have a better understanding of why things work the way they do and how to avoid these particular pitfalls. You might even learn some new tricks!