We’ll first define what we mean by the term string. Rust has only one string type in the core language, which is the string slice
strthat is usually seen in its borrowed form
&str. In Chapter 4, we talked about string slices, which are references to some UTF-8 encoded string data stored elsewhere. String literals, for example, are stored in the program’s binary and are therefore string slices.
Stringtype, which is provided by Rust’s standard library rather than coded into the core language, is a growable, mutable, owned, UTF-8 encoded string type. When Rustaceans refer to “strings” in Rust, they might be referring to either the
Stringor the string slice
&strtypes, not just one of those types. Although this section is largely about
String, both types are used heavily in Rust’s standard library, and both
Stringand string slices are UTF-8 encoded.