Futures Explained in 200 Lines of Rust

This book aims to explain Futures in Rust using an example driven approach, exploring why they're designed the way they are, the alternatives and how they work.

Going into the level of detail I do in this book is not needed to use futures or async/await in Rust. It's for the curious out there that want to know how it all works.

What this book covers

This book will try to explain everything you might wonder about up until the topic of different types of executors and runtimes. We'll just implement a very simple runtime in this book introducing some concepts but it's enough to get started.

Stjepan Glavina has made an excellent series of articles about async runtimes and executors, and if the rumors are right he's even working on a new async runtime that should be easy enough to use as learning material.

The way you should go about it is to read this book first, then continue reading the articles from stejpang to learn more about runtimes and how they work, especially:

  1. Build your own block_on()
  2. Build your own executor

I've limited myself to a 200 line main example (hence the title) to limit the scope and introduce an example that can easily be explored further.

However, there is a lot to digest and it's not what I would call easy, but we'll take everything step by step so get a cup of tea and relax.

I hope you enjoy the ride.

This book is developed in the open, and contributions are welcome. You'll find the repository for the book itself here. The final example which you can clone, fork or copy can be found here. Any suggestions or improvements can be filed as a PR or in the issue tracker for the book.

Reader exercises and further reading

In the last chapter I've taken the liberty to suggest some small exercises if you want to explore a little further.

This book is also the fourth book I have written about concurrent programming in Rust. If you like it, you might want to check out the others as well:

Credits and thanks

I'll like to take the chance of thanking the people behind mio, tokio, async_std, Futures, libc, crossbeam and many other libraries which so much is built upon.

A special thanks to Johnhoo who was kind enough to give me some feedback on an early draft of this book. He has not read the finished product and has in no way endorsed it, but a thanks is definitely due.