String

Before moving on to improve our interpreter, this chapter pauses to discuss the string type in Lua in detail. In a high-level language like Lua, strings are easy to use; but in a low-level language like Rust, strings are not so simple. Here is a quote from "Rust Programming Language":

New Rustaceans commonly get stuck on strings for a combination of three reasons: Rust’s propensity for exposing possible errors, strings being a more complicated data structure than many programmers give them credit for, and UTF-8. These factors combine in a way that can seem difficult when you’re coming from other programming languages.

Implementing and optimizing strings in the Lua interpreter is a great opportunity to explore Rust strings.

Based on the definition of string type, this chapter will also make an important decision: use Rc to implement garbage collection.