Book Image

Rust Standard Library Cookbook

By : Jan Hohenheim, Daniel Durante
Book Image

Rust Standard Library Cookbook

By: Jan Hohenheim, Daniel Durante

Overview of this book

Mozilla’s Rust is gaining much attention with amazing features and a powerful library. This book will take you through varied recipes to teach you how to leverage the Standard library to implement efficient solutions. The book begins with a brief look at the basic modules of the Standard library and collections. From here, the recipes will cover packages that support file/directory handling and interaction through parsing. You will learn about packages related to advanced data structures, error handling, and networking. You will also learn to work with futures and experimental nightly features. The book also covers the most relevant external crates in Rust. By the end of the book, you will be proficient at using the Rust Standard library.
Table of Contents (12 chapters)

There's more...

Despite its nice usability, RwLock is still no silver bullet for all concurrent problems. There is a concept in concurrent programming called deadlock. It arises when two processes wait for the unlocking of resources that the other holds. This will lead to them waiting forever, as no one is ready to take the first step. Kind of like teenagers in love. An example of this would be a writer_a requesting access to a file that writer_b holds. writer_b, in the meantime, needs some kind of user information from writer_a before he can give up the file lock. The best way to avoid this problem is to keep it in the back of your mind and remember it when you're about to create processes that depend on each other.

Another lock that is fairly popular in other languages is the Mutex, which Rust also provides under std::sync::Mutex. When it locks resources, it treats every process like a writer, so no two threads will ever be able to work at the same time with a Mutex, even...