blob: 0cddb0f497e17ec20fb48729564b8901291d83e6 [file] [log] [blame] [view] [edit]
# Common Collections
Rusts standard library includes a number of very useful data structures called
_collections_. Most other data types represent one specific value, but
collections can contain multiple values. Unlike the built-in array and tuple
types, the data these collections point to is stored on the heap, which means
the amount of data does not need to be known at compile time and can grow or
shrink as the program runs. Each kind of collection has different capabilities
and costs, and choosing an appropriate one for your current situation is a skill
youll develop over time. In this chapter, well discuss three collections that
are used very often in Rust programs:
* A _vector_ allows you to store a variable number of values next to each other.
* A _string_ is a collection of characters. Weve mentioned the `String` type
previously, but in this chapter well talk about it in depth.
* A _hash map_ allows you to associate a value with a specific key. Its a
particular implementation of the more general data structure called a _map_.
To learn about the other kinds of collections provided by the standard library,
see [the documentation][collections].
Well discuss how to create and update vectors, strings, and hash maps, as well
as what makes each special.
[collections]: ../std/collections/index.html