1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-16 07:36:05 +02:00

Update box.md (#363)

This commit is contained in:
Charisee Chiw 2023-02-09 12:55:19 -08:00 committed by GitHub
parent 736de71c7c
commit e3b4b6a5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,5 +33,7 @@ from `T` directly on a `Box<T>`][2].
* `Box` is like `std::unique_ptr` in C++.
* In the above example, you can even leave out the `*` in the `println!` statement thanks to `Deref`.
* A `Box` can be useful when you:
* have a type whose size that can't be known at compile time, but the Rust compiler wants to know an exact size.
* want to transfer ownership of a large amount of data. To avoid copying large amounts of data on the stack, instead store the data on the heap in a `Box` so only the pointer is moved.
</details>