Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
0xf90c committed Apr 24, 2024
1 parent fdeec23 commit 585741f
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions rustbook-uz/src/ch15-04-rc.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ Ushbu kodni kompilyatsiya qilsak, biz yuqoridagi xatolikni ko'ramiz:

Buning o'rniga havolalarni ushlab turish uchun `Cons` ta'rifini o'zgartirishimiz mumkin, lekin keyin biz layvtaym parametrlarini ko'rsatishimiz kerak bo'ladi. Layvtaym parametrlarini belgilash orqali, biz ro'yxatdagi har bir elementning yashashini ko'rsatamiz. 15-17 ro'yxatda ko'rsatilganidek bu elementlar va ro'yxatlarga tegishli, lekin har doim gam emas.

Instead, we’ll change our definition of `List` to use `Rc<T>` in place of
`Box<T>`, as shown in Listing 15-18. Each `Cons` variant will now hold a value
and an `Rc<T>` pointing to a `List`. When we create `b`, instead of taking
ownership of `a`, we’ll clone the `Rc<List>` that `a` is holding, thereby
increasing the number of references from one to two and letting `a` and `b`
share ownership of the data in that `Rc<List>`. We’ll also clone `a` when
creating `c`, increasing the number of references from two to three. Every time
we call `Rc::clone`, the reference count to the data within the `Rc<List>` will
increase, and the data won’t be cleaned up unless there are zero references to
it.
15-18-ro'yxatda ko'rsatilganidek, `Box<T>`ning o'rniga`Rc<T>`ni ishlatish uchun biz bizning `Ro'yxat`imizning mazmunini o'zgartiramiz. Har bir `Cons` varianti qiymatni o'zida ushlab turadi va `Rc<T>` `Ro'yxat`ni ko'rsatadi. `a`ning egaligini olishning o'rniga `b`ni yaratganimizda, `a` ni ushlab turgan `Rc<List>`ni klonlaymiz, shu bilan birga referenslar sonini birdan ikkiga ko'paytiramiz va `Rc<List>`dagi ma'lumotlarning egaligini ulashish uchun `a` va `b`ga ruxsat beramiz. referenslar sonini ikkidan uchga ko'paytirgan holda, `c`ni yaratayotganimizda `a`ni ham klonlaymiz. `Rc::clone`ni har safar chaqirganimizda, `Rc<List>` tarkibidagi ma'lumotlarining referenslari soni oshiriladi, zero referenslar paydo bo'lmagungacha ma'lumotlar tozalanmaydi.

<span class="filename">Filename: src/main.rs</span>

Expand Down

0 comments on commit 585741f

Please sign in to comment.