-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
- I have searched open and closed issues and pull requests for duplicates, using these search terms:
- 3.2
- "3.2"
- stack rather
- stack rather than heap
- flexible
- I have checked the latest
main
branch to see if this has already been fixed, in this file:book/src/ch03-02-data-types.md
URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch03-02-data-types.html#the-array-type
Description of the problem:
After first reading it seemed that the first sentence compares array to tuple, but not vector, and only in the second sentence vector is mentioned. Also, I'm not sure about the usefulness of the pre-last sentence, as the difference becomes clear after reading chapter 4.
Arrays are useful when you want your data allocated on the stack rather than the heap (we will discuss the stack and the heap more in Chapter 4) or when you want to ensure you always have a fixed number of elements. An array isn’t as flexible as the vector type, though. A vector is a similar collection type provided by the standard library that is allowed to grow or shrink in size. If you’re unsure whether to use an array or a vector, chances are you should use a vector. Chapter 8 discusses vectors in more detail.
Suggested fix:
We need to clarify that an array isn’t as flexible as the vector type. A vector is a similar collection type provided by the standard library that is allowed to grow or shrink in size. But arrays are useful when you want your data allocated on the stack rather than the heap (we will discuss the stack and the heap more in Chapter 4) or when you want to ensure you always have a fixed number of elements. Chapter 8 discusses vectors in more detail.