Skip to content

Commit cedc798

Browse files
committed
Merge pull request #21031 from steveklabnik/gh19067
Improve clarity of paragraph in the pointer guide Reviewed-by: Gankro
2 parents 8f0fe72 + db7de96 commit cedc798

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/doc/trpl/pointers.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,10 @@ fn main() {
721721
This gives you flexibility without sacrificing performance.
722722

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

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

0 commit comments

Comments
 (0)