1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-18 20:39:35 +02:00

Remove an incorrect note (#1580)

People are often confused by this: the fact that we can remove the `*`
in the `println!()` is not because the compiler auto-derefs here (it
does not), but because `Display` is implemented for `&T where T:
Display` (a blanket implementation).
This commit is contained in:
Chayim Refael Friedman 2023-12-12 18:29:50 +02:00 committed by GitHub
parent c342a74b3e
commit 86289b4814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,6 @@ fn main() {
<details>
* `Box` is like `std::unique_ptr` in C++, except that it's guaranteed to be not null.
* 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.