From 9bc2bf7138ed9e0e122eebb7b11da6668c98f1d0 Mon Sep 17 00:00:00 2001 From: funkill2 Date: Sat, 7 Dec 2024 04:00:17 +0300 Subject: [PATCH] update original --- rustbook-en/src/ch15-05-interior-mutability.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/rustbook-en/src/ch15-05-interior-mutability.md b/rustbook-en/src/ch15-05-interior-mutability.md index f1d5547c..77180db9 100644 --- a/rustbook-en/src/ch15-05-interior-mutability.md +++ b/rustbook-en/src/ch15-05-interior-mutability.md @@ -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`, and then the `send` method will be