Rust Standard Library Cookbook

Book description

Explore the Rust Standard library and compose algorithms with minimal dependency on external libraries

Key Features

  • Develop high-quality, fast, and portable applications by leveraging the power of Rust's Standard library.
  • Practical recipes that will help you work with the Standard library to boost your productivity as a Rust developer.
  • Learn about most relevant external crates to be used along with the Standard library.

Book Description

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.

What you will learn

  • How to use the basic modules of the library: strings, command line access, and more.
  • Implement collections and folding of collections using vectors, Deque, linked lists, and more.
  • Handle various file types, compressing, and decompressing data.
  • Search for files with glob patterns.
  • Implement parsing through various formats such as CSV, TOML, and JSON.
  • Utilize drop trait, the Rust version of destructor.
  • Resource locking with Bilocks.

Who this book is for

This book is for developers who would like to explore the power of Rust and learn to use the STL for various functionalities. A basic Rust programming knowledge is assumed.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Rust Standard Library Cookbook
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Sections
    7. Getting ready
    8. How to do it…
    9. How it works…
    10. There's more…
    11. See also
    12. Get in touch
    13. Reviews
    14. Disclaimer
  6. Learning the Basics
    1. Introduction
    2. Concatenating strings
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. Using the format! macro
    7. How to do it...
    8. How it works...
    9. There's more...
    10. Providing a default implementation
    11. How to do it...
    12. How it works...
    13. Using the constructor pattern
    14. Getting ready
    15. How to do it...
    16. How it works...
    17. There's more...
    18. See also
    19. Using the builder pattern
    20. How to do it...
    21. How it works...
    22. There's more...
    23. Parallelism through simple threads
    24. How to do it...
    25. How it works...
    26. There's more...
    27. See also
    28. Generating random numbers
    29. How to do it...
    30. How it works...
    31. There's more...
    32. Querying with regexes
    33. Getting ready
    34. How to do it...
    35. How it works...
    36. There's more...
    37. See also
    38. Accessing the command line
    39. How to do it...
    40. How it works...
    41. There's more...
    42. Interacting with environment variables
    43. How to do it...
    44. How it works...
    45. There's more...
    46. Reading from stdin
    47. How to do it...
    48. How it works...
    49. There's more...
    50. See also
    51. Accepting a variable number of arguments
    52. Getting started
    53. How to do it...
    54. How it works...
    55. There's more...
    56. See also
  7. Working with Collections
    1. Introduction
    2. Using a vector
    3. How to do it...
    4. How it works...
    5. There's more...
    6. Using a string
    7. How to do it...
    8. How it works...
    9. There's more...
    10. Accessing collections as iterators
    11. How to do it...
    12. How it works...
    13. There's more...
    14. See also
    15. Using a VecDeque
    16. How to do it...
    17. How it works...
    18. There's more...
    19. Using a HashMap
    20. How to do it...
    21. How it works...
    22. There's more...
    23. Using a HashSet
    24. How to do it...
    25. How it works...
    26. There's more...
    27. Creating an own iterator
    28. How to do it...
    29. How it works...
    30. There's more...
    31. Using a slab
    32. How to do it...
    33. How it works...
    34. There's more...
  8. Handling Files and the Filesystem
    1. Introduction
    2. Working with text files
    3. How to do it...
    4. How it works...
    5. There's more...
    6. See also
    7. Handling bytes
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. There's more...
    12. Working with binary files
    13. How to do it...
    14. How it works...
    15. There's more...
    16. See also
    17. Compressing and decompressing data
    18. How to do it...
    19. How it works...
    20. There's more...
    21. Traversing the filesystem
    22. Getting ready
    23. How to do it...
    24. How it works...
    25. There's more...
    26. See also
    27. Finding files with glob patterns
    28. How to do it...
    29. How it works...
    30. See also
  9. Serialization
    1. Introduction
    2. Working with CSV
    3. Getting started
    4. How to do it...
    5. How it works...
    6. There's more...
    7. See also
    8. Serialization basics with Serde
    9. How to do it...
    10. How it works...
    11. There's more...
    12. See also
    13. Working with TOML
    14. Getting started
    15. How to do it...
    16. How it works...
    17. There's more...
    18. See also
    19. Working with JSON
    20. Getting ready
    21. How to do it...
    22. How it works...
    23. There's more...
    24. See also
    25. Building JSON dynamically
    26. How to do it...
    27. How it works...
    28. See also
  10. Advanced Data Structures
    1. Introduction
    2. Creating lazy static objects
    3. How to do it...
    4. How it works...
    5. There's more...
    6. See also
    7. Working with bit fields
    8. Getting started
    9. How to do it...
    10. How it works...
    11. See also
    12. Providing custom derives
    13. Getting started
    14. How to do it...
    15. How it works...
    16. There's more...
    17. Converting types into each other
    18. How to do it...
    19. How it works...
    20. Boxing data
    21. How to do it...
    22. How it works...
    23. There's more...
    24. See also
    25. Sharing ownership with smart pointers
    26. How to do it...
    27. How it works...
    28. There's more...
    29. See also
    30. Working with interior mutability
    31. How to do it...
    32. How it works...
    33. There's more...
    34. See also
  11. Handling Errors
    1. Introduction
    2. Providing user-defined error types
    3. How to do it...
    4. How it works...
    5. There's more...
    6. Providing logging
    7. How to do it...
    8. How it works...
    9. There's more...
    10. Creating a custom logger
    11. How to do it...
    12. How it works...
    13. There's more...
    14. See also
    15. Implementing the Drop trait
    16. How to do it...
    17. How it works...
    18. There's more...
    19. See also
    20. Understanding RAII
    21. How to do it...
    22. How it works...
    23. There's more...
    24. See also
  12. Parallelism and Rayon
    1. Introduction
    2. Parallelizing iterators
    3. How to do it...
    4. How it works...
    5. See also
    6. Running two operations together
    7. How to do it...
    8. How it works...
    9. There's more...
    10. See also
    11. Sharing resources in multithreaded closures
    12. How to do it...
    13. How it works...
    14. See also
    15. Sending data across threads
    16. How to do it...
    17. How it works...
    18. There's more...
    19. See also
    20. Accessing resources in parallel with RwLocks
    21. How to do it...
    22. How it works...
    23. There's more...
    24. See also
    25. Atomically accessing primitives
    26. How to do it...
    27. How it works...
    28. There's more...
    29. See also
    30. Putting it all together in a connection handler
    31. How to do it...
    32. How it works...
    33. There's more...
  13. Working with Futures
    1. Introduction
    2. Providing futures with a CPU pool and waiting for them
    3. How to do it...
    4. How it works...
    5. Handling errors in futures
    6. How to do it...
    7. How it works...
    8. See also
    9. Combining futures
    10. How to do it...
    11. How it works...
    12. See also
    13. Using Streams
    14. How to do it...
    15. How it works...
    16. Using Sinks
    17. How to do it...
    18. How it works...
    19. Using the oneshot channel
    20. How to do it...
    21. How it works...
    22. Returning futures
    23. How to do it...
    24. How it works...
    25. There's more...
    26. See also
    27. Locking resources with BiLocks
    28. How to do it...
    29. How it works...
  14. Networking
    1. Introduction
    2. Setting up a basic HTTP server
    3. Getting ready
    4. How to do it...
    5. How it works...
    6. See also
    7. Configuring an HTTP server to perform echoing and routing
    8. Getting ready
    9. How to do it...
    10. How it works...
    11. Configuring an HTTP server to perform file serving
    12. How to do it...
    13. How it works...
    14. There's more...
    15. See also
    16. Making requests to APIs
    17. How to do it...
    18. How it works...
    19. There's more...
    20. See also
  15. Using Experimental Nightly Features
    1. Introduction
    2. Iterating over an inclusive range
    3. How to do it...
    4. How it works...
    5. See also
    6. Returning abstract types
    7. How to do it...
    8. How it works...
    9. There's more...
    10. See also
    11. Composing functions
    12. How to do it...
    13. How it works...
    14. See also
    15. Filtering strings efficiently
    16. How to do it...
    17. How it works...
    18. See also
    19. Stepping through an iterator in regular intervals
    20. How to do it...
    21. How it works...
    22. See also
    23. Benchmarking your code
    24. How to do it...
    25. How it works...
    26. There's more...
    27. See also
    28. Using generators
    29. How to do it...
    30. How it works...
    31. See also
  16. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Rust Standard Library Cookbook
  • Author(s): Jan Hohenheim, Daniel Durante
  • Release date: March 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788623926