Rust Guide

The Rust Book

Almost everyone learns Rust by reading The Rust Book, affectionately known as "the book" inside the Rust community:

https://doc.rust-lang.org/book/

I also found it helpful to jump through Rust By Example as a companion text:

https://doc.rust-lang.org/rust-by-example/

It's a bunch of code examples that are designed to illustrate language features. The examples are commented with some light exposition, so it could be an alternative to parts of The Rust Book if you're short on time.

More on Ownership

To get a deeper understanding of ownership, check out the Nomicon:

https://doc.rust-lang.org/nomicon/ownership.html

In particular, the subsection on Aliasing gives the formal definition of what it means to alias in Rust:

Variables and pointers alias if they refer to overlapping regions of memory.

Thus when working with the borrow checker, the programmer is fundamentally reasoning about memory regions. This explains why &mut arr and &mut arr[2] are aliases, even though they're syntactically borrowing different objects.

Here's another post that helps motivate why shared mutability is problematic:

https://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/

Async Rust

Since we're building high concurrency network services in Rust, we heavily use "Async Rust" which is a collection of language features + ecosystem libraries for dealing with asynchronous I/O.

Async Rust is not covered in The Rust Book, so instead I've collected a series of resources I found to be most helpful:

  1. Start by watching Withoutboats's overview of Async Rust.

  2. Then watch this video by Jon Gjengset on the semantics of async/await.

  3. Skim through the Async Rust Book.

  4. Go through the Tokio tutorial.

  5. Check that you're able to completely understand the mini-redis codebase.

  6. Read Alice Ryhl's blog post on implementing Actors with Tokio, which I've found to be a dominant pattern in practice. For example, all the handlers in mini-redis are instances of this pattern. This post is also a good mental model for how channels are used in practice.

Supplemental material:

  • Jon Gjengset's video on Async Rust (less up-to-date but more in-depth than the one above)
  • Jon Gjengset's video on pinning
  • Eliza Weisman's talk on tokio-tracing

Other resources