Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf90c committed Jan 11, 2025
1 parent ee9c796 commit 79c1e53
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rustbook-uz/src/ch15-05-interior-mutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ Then we create a new `LimitTracker` and give it a reference to the new
we assert that the list of messages that the `MockMessenger` is keeping track
of should now have one message in it.

Sinovda biz “LimitTracker”ga “qiymat”ni “maksimal” qiymatining 75 foizidan ko‘prog‘iga o‘rnatish buyurilganda nima sodir bo‘lishini sinab ko‘ramiz. Birinchidan, biz yangi "MockMessenger" ni yaratamiz, u xabarlarning bo'sh ro'yxati bilan boshlanadi. Keyin biz yangi `LimitTracker` yaratamiz va unga yangi `MockMessenger` va `max` qiymati 100 ga havola beramiz. 100ning 75 foizi. Keyin biz “MockMessenger” kuzatayotgan xabarlar roʻyxatida bitta xabar boʻlishi kerakligini taʼkidlaymiz. unda.

However, there’s one problem with this test, as shown here:
Biroq, bu testda ko'rsatilganidek, bitta muammo bor:

```console
{{#include ../listings/ch15-smart-pointers/listing-15-21/output.txt}}
Expand All @@ -150,6 +153,8 @@ 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).

Biz “MockMessenger”ni xabarlarni kuzatib borish uchun o‘zgartira olmaymiz, chunki “yuborish” usuli “o‘z”ga o‘zgarmas havolani oladi. Shuningdek, xato matnidagi “&mut self” dan foydalanish taklifini qabul qila olmaymiz, chunki “yuborish” imzosi “Messenger” xususiyati taʼrifidagi imzoga toʻgʻri kelmasdi (xato boʻlganini koʻring. xabar olasiz).

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
able to modify `sent_messages` to store the messages we’ve seen. Listing 15-22
Expand Down

0 comments on commit 79c1e53

Please sign in to comment.