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

If you ran into trouble while running this recipe, you can use David Tolney's cargo-expand (https://github.com/dtolnay/cargo-expand) to show you how the compiler expanded your proc_macros. It's a really useful tool to debug your macros, so be sure to check it out.

The reason behind the two-crate restriction is historical and only temporary. In the beginning, there was only one way to define macros, macro_rules!. People with exotic needs, who were ready to put in the effort, were (and still are) able to extend their programs by directly hooking into the Rust compiler itself. Crates written this way are called compiler plugins. Of course, this is incredibly unstable because every minor Rust release can break your plugin, but people kept on doing it because it gave them one big advantage, custom derives. The core team reacted to the increased demand for language extensibility by deciding to launch macros2.0 at some point in the future, bringing an overhaul...