Most errors aren’t serious enough to require the program to stop entirely. Sometimes, when a function fails, it’s for a reason that you can easily interpret and respond to.
Rust has two string types, a string slice (&str) and an owned string (String). We’re not going to dictate when you should use which one, but we’ll show you how to identify and create them, as well as use them.
Rust’s 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.
This exercise will get you familiar with two fundamental data structures that are used very often in Rust programs:
A vector allows you to store a variable number of values next to each other. A hash map allows you to associate a value with a particular key. You may also know this by the names unordered map in C++, dictionary in Python, or an associative array in other languages.
Rust has a number of features that allow you to manage your code’s organization, including which details are exposed, which details are private, and what names are in each scope in your programs. These features, sometimes collectively referred to as the module system, include:
Packages: A Cargo feature that lets you build, test, and share crates
Crates: A tree of modules that produces a library or executable
Modules and use: Let you control the organization, scope, and privacy of paths
Paths: A way of naming an item, such as a struct, function, or module
Rust allows you to define types called enums which enumerate possible values. Useful in combination with enums is Rust’s pattern matching facility, which makes it easy to run different code for different values of an enumeration.