Skip to content

Commit

Permalink
Merge pull request #4142 from rust-lang/improved-error-message
Browse files Browse the repository at this point in the history
Ch. 15.5: account for improved error message
  • Loading branch information
chriskrycho authored Dec 6, 2024
2 parents 139538d + d8f0f5b commit 6cc1bb8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/ch15-05-interior-mutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,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` in both the `impl` method and
the `trait` definition. We do not want to change the `Messenger` trait solely
for the sake of testing. Instead, we need to find a way to make our test code
work correctly with our existing design.

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

0 comments on commit 6cc1bb8

Please sign in to comment.