Skip to content
Open
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
6 changes: 4 additions & 2 deletions quizzes/ch10-04-inventory.toml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ println!("{:?}", result.scores);
context = """
This program is actually safe as written. It is a limitation of the borrow checker to not understand that `get_curve`
only borrows `curve`, and doesn't affect `scores`. However, in theory if `get_curve` were changed to return a reference
to something with `self.scores`, then memory safety could potentially be violated.
to something with `self.scores`, then memory safety could potentially be violated. Note that
the `let x = &result.scores[0];` program would not compile, as Rust's borrow checker would not
allow to borrow `result` as mutable while immutable borrow of `result` exists.
"""

[[questions]]
Expand Down Expand Up @@ -383,4 +385,4 @@ so it allows the function to compile. This is a common workaround for this type

Another option is to leverage the fact that `self.curve` is cheap to copy and use [`Option::copied`](https://doc.rust-lang.org/std/option/enum.Option.html#method.copied),
which would release the borrow on `self` as soon as `.copied()` is called.
"""
"""