Working with Collections

In this chapter, we will cover the following recipes:

  • 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

Introduction

Rust provides a very broad set of collections to use. We will look at most of them, see how they're used, discuss how they're implemented, and when to use and choose them. A big part of this chapter focuses on iterators. Much of Rust's flexibility comes from them, as all collections (and more!) can be used as iterators. Learning how to use them is crucial.

Throughout this chapter, we are going to use the big O notation to show how effective certain algorithms are. In case you don't know it yet, it ...

Get Rust Standard Library Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.