1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-22 15:57:46 +02:00

Update box-recursive.md (#360)

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

View File

@ -32,10 +32,12 @@ fn main() {
<details> <details>
If the `Box` was not used here and we attempted to embed a `List` directly into the `List`, * If the `Box` was not used here and we attempted to embed a `List` directly into the `List`,
the compiler would not compute a fixed size of the struct in memory, it would look infinite. the compiler would not compute a fixed size of the struct in memory, it would look infinite.
`Box` solves this problem as it has the same size as a regular pointer and just points at the next * `Box` solves this problem as it has the same size as a regular pointer and just points at the next
element of the `List` in the heap. element of the `List` in the heap.
* Remove the `Box` in the List definition and show the compiler error. `Recursive with indirection` is a hint you might want to use a Box or reference of some kind, instead of storing a value directly.
</details> </details>