Название: Rust Standard Library Cookbook Автор: Jan Nils Ferner, Daniel Durante Издательство: packpub Жанр: Программирование Год издания: 2018 Страниц: 354 Язык: Английский Формат: FB2/RTF/PDF Размер: 11 Мб
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.
1: LEARNING THE BASICS Introduction Concatenating strings Using the format! macro Providing a default implementation Using the constructor pattern Using the builder pattern Parallelism through simple threads Generating random numbers Querying with regexes Accessing the command line Interacting with environment variables Reading from stdin Accepting a variable number of arguments 2: WORKING WITH COLLECTIONS Introduction Using a vector Using a string Accessing collections as iterators Using a VecDeque Using a HashMap Using a HashSet Creating an own iterator Using a slab 3: HANDLING FILES AND THE FILESYSTEM Introduction Working with text files Handling bytes Working with binary files Compressing and decompressing data Traversing the filesystem Finding files with glob patterns 4: SERIALIZATION Introduction Working with CSV Serialization basics with Serde Working with TOML Working with JSON Building JSON dynamically 5: ADVANCED DATA STRUCTURES Introduction Creating lazy static objects Working with bit fields Providing custom derives Converting types into each other Boxing data Sharing ownership with smart pointers Working with interior mutability 6: HANDLING ERRORS Introduction Providing user-defined error types Providing logging Creating a custom logger Implementing the Drop trait Understanding RAII 7: PARALLELISM AND RAYON Introduction Parallelizing iterators Running two operations together Sharing resources in multithreaded closures Sending data across threads Accessing resources in parallel with RwLocks Atomically accessing primitives Putting it all together in a connection handler 8: WORKING WITH FUTURES Introduction Providing futures with a CPU pool and waiting for them Handling errors in futures Combining futures Using Streams Using Sinks Using the oneshot channel Returning futures Locking resources with BiLocks 9: NETWORKING Introduction Setting up a basic HTTP server Configuring an HTTP server to perform echoing and routing Configuring an HTTP server to perform file serving Making requests to APIs 10: USING EXPERIMENTAL NIGHTLY FEATURES Introduction Iterating over an inclusive range Returning abstract types Composing functions Filtering strings efficiently Stepping through an iterator in regular intervals Benchmarking your code Using generators