Skip to content

Commit

Permalink
Clarify that it's not stack/heap exactly that matters for copy/non co…
Browse files Browse the repository at this point in the history
…py, fixes #2799
  • Loading branch information
carols10cents committed Jul 25, 2021
1 parent 13b2ee2 commit 2fa3d36
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ch04-01-what-is-ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ understanding by introducing the `String` type.

To illustrate the rules of ownership, we need a data type that is more complex
than the ones we covered in the [“Data Types”][data-types]<!-- ignore -->
section of Chapter 3. The types covered previously are all stored on the stack
and popped off the stack when their scope is over, but we want to look at data
that is stored on the heap and explore how Rust knows when to clean up that
data.
section of Chapter 3. The types covered previously are all a known size, can be
stored on the stack and popped off the stack when their scope is over, and can
be quickly and trivially copied to make a new, independent instance if another
part of code needs to use the same value in a different scope. But we want to
look at data that is stored on the heap and explore how Rust knows when to
clean up that data.

We’ll use `String` as the example here and concentrate on the parts of `String`
that relate to ownership. These aspects also apply to other complex data types,
Expand All @@ -151,10 +153,10 @@ program. String literals are convenient, but they aren’t suitable for every
situation in which we may want to use text. One reason is that they’re
immutable. Another is that not every string value can be known when we write
our code: for example, what if we want to take user input and store it? 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. You can create a `String` from a string literal
using the `from` function, like so:
these situations, Rust has a second string type, `String`. This type manages
data allocated on the heap and as such is able to store an amount of text that
is unknown to us at compile time. You can create a `String` from a string
literal using the `from` function, like so:

```rust
let s = String::from("hello");
Expand Down

0 comments on commit 2fa3d36

Please sign in to comment.