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...

A channel is not Sync and, as such, can only be moved across channels but not shared between them. If you need the channel to be Sync you can use std::sync::mpsc::sync_channel, which blocks when a buffer of unanswered messages is full. An example for when this might be necessary is when a web framework offers to manage your types but only works with Sync structs. You can read more on Sync in the recipe Atomically access primitives.

The mpsc channels, as their name suggests, allow many senders but only one receiver. Most of the time, this will be good enough, but if you find yourself needing the exact opposite, as in one sender and multiple receivers, check out Sean McArthur's spmc crate at https://crates.io/crates/spmc, which provides you with Single-producer, multi-consumer channels.