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)

How it works...

Within our send_example() function:

  • On lines 13 through 15, we set up three oneshot channels.
  • On lines 20 through 23 we use futures::stream::futures_ordered, which will convert a list (any IntoIterator value) of futures into a Stream yielding results on a first in, first out (FIFO) basis. If any underlying futures do not complete before the next future is invoked, this function will wait until the long-running future has been completed and will then internally re-sort that future into its proper order.
  • Line 25 shows us that we can push additional futures into the futures_ordered iterator separately.
  • Line 28 demonstrates another function that doesn't rely on sorting on a FIFO basis, called futures::stream::futures_unordered. This function will have better performance than its counterpart futures_ordered, but for our example, we are not sending enough values to make a difference.
  • On lines 31 through 33 we send values to our channels, mimicking the process of returning...