File tree 1 file changed +4
-5
lines changed
1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -721,11 +721,10 @@ fn main() {
721
721
This gives you flexibility without sacrificing performance.
722
722
723
723
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> ` .
729
728
730
729
This is important enough that it bears repeating: pointers are not for
731
730
optimizing returning values from your code. Allow the caller to choose how they
You can’t perform that action at this time.
0 commit comments