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

You might have noticed that returning a Box<Iterator> or a Box<Error> comes at a small cost in terms of efficiency, as it requires moving an object onto the heap without it having any reason to go there. There are currently two ways around this.

For Box<Error>, you should instead create an own Error type, combining all the possible errors that can be returned from your function. This is detailed in Chapter 6, Handling Errors; Providing user-defined Error types.

For Box<Iterator>, you can analyze the compiler's output in order to find out the exact true type that you're returning. This works for small iterators, but any complex iterator will take a long time to crack. Because this situation is not really desirable, the Rust team has approved the introduction of abstract types, which will be introduced in Chapter 10, Using Experimental Nightly Features; Returning abstract types because it has not yet hit stable Rust.