Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformulate speaker notes regarding Box #1819

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/smart-pointers/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ fn main() {
so only the pointer is moved.

- If `Box` was not used and we attempted to embed a `List` directly into the
`List`, the compiler would not compute a fixed size of the struct in memory
(`List` would be of infinite size).
`List`, the compiler would not be able to compute a fixed size for the struct
in memory (the `List` would be of infinite size).

- `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.

- 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.
- Remove the `Box` in the List definition and show the compiler error. We get
the message "recursive without indirection", because for data recursion, we
have to use indirection, a Box or reference of some kind, instead of storing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small drive-by formatting fix (feel free to include this here or in another PR):

Suggested change
have to use indirection, a Box or reference of some kind, instead of storing
have to use indirection, a `Box` or reference of some kind, instead of storing

the value directly.

# More to Explore

Expand Down