There're sentences like
The types covered previously are all stored on the stack and popped off the stack when their scope is over
For these situations, Rust has a second string type, String. This type is allocated on the heap and as such is able to store an amount of text that is unknown to us at compile time.
I'm sympathetic of what it's trying to say. But with all the new features like async fn coming in, this is doing more harm than good to beginners. For example, any async fn local variables may actually live on heap, when it's part of a boxed future that uses heap storage.
Basically a more correct understanding for beginners would be:
-
A specifc value with any type can be stored anywhere as long as there's a place with corresponding type. The type doesn't limit where such a place could come from at all.
-
Some types (like Box<T> or String or Vec<T>) manages and provides places on the heap, and these places can be used to contain values. For example, String manages such places, containing an amount of text.
cc #1963
There're sentences like
I'm sympathetic of what it's trying to say. But with all the new features like
async fncoming in, this is doing more harm than good to beginners. For example, any async fn local variables may actually live on heap, when it's part of a boxed future that uses heap storage.Basically a more correct understanding for beginners would be:
A specifc value with any type can be stored anywhere as long as there's a place with corresponding type. The type doesn't limit where such a place could come from at all.
Some types (like
Box<T>orStringorVec<T>) manages and provides places on the heap, and these places can be used to contain values. For example, String manages such places, containing an amount of text.cc #1963