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

Chapter 15-05: Fix incorrect interpretation of compiler error #3501

Merged
merged 1 commit into from
Apr 17, 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
7 changes: 4 additions & 3 deletions src/ch15-05-interior-mutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ However, there’s one problem with this test, as shown here:

We can’t modify the `MockMessenger` to keep track of the messages, because the
`send` method takes an immutable reference to `self`. We also can’t take the
suggestion from the error text to use `&mut self` instead, because then the
signature of `send` wouldn’t match the signature in the `Messenger` trait
definition (feel free to try and see what error message you get).
suggestion from the error text to use `&mut self` instead, because we are
testing an API and it's not a good idea to modify the API for the sole purpose
of testing. Usually, the test engineers do not have permission to modify the
API they're testing. Feel free to try and see what error message you get.

This is a situation in which interior mutability can help! We’ll store the
`sent_messages` within a `RefCell<T>`, and then the `send` method will be
Expand Down