18.7 Summary
Rust's standard library provides a range of generic, dynamic collection types—Vec<T>
, String
, HashMap<K, V>
, and others—that extend beyond primitive, fixed-size arrays and tuples. By understanding their performance characteristics, memory requirements, and usage patterns, you can select the optimal collection for your use case.
All these collections maintain Rust's safety guarantees, manage their memory automatically, and provide a rich set of operations. Knowing when to use each type, along with considerations like zero-based indexing, usize
indexing, generic parameterization, and ownership rules, will help you write more efficient, maintainable, and idiomatic Rust code.