3 More complex types

 

This chapter covers

  • Arrays—simple, fast, immutable collections of the same type
  • Vectors—similar to arrays but growable and with more functionality
  • Tuples (a grouping of various types)
  • Control flow—making your code run differently depending on the situation

We’re now moving past Rust’s simplest types to collection types. Rust has a lot of collection types, and in this chapter, we’ll learn three of them: arrays, vectors, and tuples. Unsurprisingly, Rust gives you a lot of options to choose from; this chapter only shows a few. After collection types, we’ll learn about control flow, which means telling Rust how to run your code depending on the situation. One of the coolest parts of control flow in Rust is the keyword match, so keep an eye out for that.

3.1 Collection types

Rust has a lot of types for making collections. Collections are used when you have more than one value and want to hold them in a single place with some sort of order. For example, you could have information on all the cities in your country inside one collection.

3.1.1 Arrays

3.1.2 Vectors

3.1.3 Tuples

3.2 Control flow

3.2.1 Basic control flow

3.2.2 Match statements

3.2.3 Loops

Summary

sitemap