Skip to content

Commit

Permalink
Improve clarity of paragraph in the pointer guide
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Jan 12, 2015
1 parent b21a6da commit db7de96
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/doc/trpl/pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,10 @@ fn main() {
This gives you flexibility without sacrificing performance.

You may think that this gives us terrible performance: return a value and then
immediately box it up ?! Isn't that the worst of both worlds? Rust is smarter
than that. There is no copy in this code. `main` allocates enough room for the
`box`, passes a pointer to that memory into `foo` as `x`, and then `foo` writes
the value straight into that pointer. This writes the return value directly into
the allocated box.
immediately box it up ?! Isn't this pattern the worst of both worlds? Rust is
smarter than that. There is no copy in this code. `main` allocates enough room
for the `box`, passes a pointer to that memory into `foo` as `x`, and then
`foo` writes the value straight into the `Box<T>`.

This is important enough that it bears repeating: pointers are not for
optimizing returning values from your code. Allow the caller to choose how they
Expand Down

1 comment on commit db7de96

@Gankra
Copy link

@Gankra Gankra commented on db7de96 Jan 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ rollup

Please sign in to comment.