From 331c7b355d1b4cfd080c398333840ff440a01f63 Mon Sep 17 00:00:00 2001 From: Abdug'ani Toshmukhamedov Date: Mon, 5 Feb 2024 23:20:38 +0500 Subject: [PATCH 1/2] docs/ch15-02-deref --- rustbook-uz/src/ch15-02-deref.md | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/rustbook-uz/src/ch15-02-deref.md b/rustbook-uz/src/ch15-02-deref.md index 23c9fe8b..0827f7aa 100644 --- a/rustbook-uz/src/ch15-02-deref.md +++ b/rustbook-uz/src/ch15-02-deref.md @@ -1,18 +1,19 @@ -## Treating Smart Pointers Like Regular References with the `Deref` Trait - -Implementing the `Deref` trait allows you to customize the behavior of the -*dereference operator* `*` (not to be confused with the multiplication or glob -operator). By implementing `Deref` in such a way that a smart pointer can be -treated like a regular reference, you can write code that operates on -references and use that code with smart pointers too. - -Let’s first look at how the dereference operator works with regular references. -Then we’ll try to define a custom type that behaves like `Box`, and see why -the dereference operator doesn’t work like a reference on our newly defined -type. We’ll explore how implementing the `Deref` trait makes it possible for -smart pointers to work in ways similar to references. Then we’ll look at -Rust’s *deref coercion* feature and how it lets us work with either references -or smart pointers. +## Smart Pointerlarni `Deref` Xususiyati Bilan Oddiy Havolalar Kabi Ishlatish + +`Deref` xususiyatini qo'llash, *dereference operatori*ning `*` (ko'paytirish +yoki glob operatori bilan adashtirmaslik kerak) xulq-atvorini sozlashga imkon +beradi. Smart pointerlarni `Deref` xususiyati bilan oddiy havolalar kabi +qo'llasangiz, siz havolalar ustida ishlaydigan kod yozishingiz, shuningdek, +ushbu kodni smart pointerlar bilan ishlatishingiz mumkin bo'ladi. + +Keling, avvalo, dereference operatori oddiy havolalar bilan qanday ishlashini +ko'rib chiqaylik. Keyin biz `Box` kabi maxsus turni e'lon qilishga harakat +qilamiz va dereference operatori nega bizning yangi e'lon qilgan turimizdagi +havola kabi ishlamayotganini ko'ramiz. Biz `Deref` xususiyatini amalga oshirish +smart pointerlarning havolalarga o'xshash tarzda ishlashiga qanday imkon +berishini ko'rib chiqamiz. Keyin biz Rustning *deref coercion* xususiyatini va +u bizga havolalar yoki smart pointerlar bilan ishlashga qanday imkon berishini +ko'rib chiqamiz. > Note: there’s one big difference between the `MyBox` type we’re about to > build and the real `Box`: our version will not store its data on the heap. From 3ea746745afcf7de236dfc8ce5423d92e6569786 Mon Sep 17 00:00:00 2001 From: Abdug'ani Toshmukhamedov Date: Wed, 7 Feb 2024 21:50:00 +0500 Subject: [PATCH 2/2] docs: translate 2 paras --- rustbook-uz/src/ch15-02-deref.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/rustbook-uz/src/ch15-02-deref.md b/rustbook-uz/src/ch15-02-deref.md index 0827f7aa..2e5592ca 100644 --- a/rustbook-uz/src/ch15-02-deref.md +++ b/rustbook-uz/src/ch15-02-deref.md @@ -15,20 +15,21 @@ berishini ko'rib chiqamiz. Keyin biz Rustning *deref coercion* xususiyatini va u bizga havolalar yoki smart pointerlar bilan ishlashga qanday imkon berishini ko'rib chiqamiz. -> Note: there’s one big difference between the `MyBox` type we’re about to -> build and the real `Box`: our version will not store its data on the heap. -> We are focusing this example on `Deref`, so where the data is actually stored -> is less important than the pointer-like behavior. +> Eslatma: biz qurmoqchi bo'lgan `MyBox` turi va haqiqiy `Box` o‘rtasida +> bitta katta farq bor: bizning versiyamiz o‘z ma’lumotlarini heapda saqlamaydi. +> Biz ushbu misolda e'tiborimizni `Deref`ga qaratmoqdamiz, shuning uchun +> ma'lumotlarning qayerda saqlanishi pointerga o'xshash xatti-harakatlardan +> kamroq ahamiyatga ega. -### Following the Pointer to the Value +### Pointerni Qiymatga bog'lash -A regular reference is a type of pointer, and one way to think of a pointer is -as an arrow to a value stored somewhere else. In Listing 15-6, we create a -reference to an `i32` value and then use the dereference operator to follow the -reference to the value: +Muntazam havola pointerning bir turi bo'lib, pointerni boshqa joyda saqlangan +qiymatga o'q kabi tasavvur qilishning bir usuli. 15-6 ro'yxatda biz `i32` +qiymatiga havola yaratamiz va keyin qiymatga havolani bog'lash uchun dereference +operatoridan foydalanamiz: Filename: src/main.rs