Skip to content

Commit 76ea680

Browse files
committed
Merge branch 'bemeritus-main'
2 parents fcc7a89 + 3c0ef83 commit 76ea680

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

rustbook-uz/src/ch17-02-trait-objects.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,16 @@ metod qayerda chaqirilishini biladi. Kompilyator bilmagan holat esa dynamic disp
255255
(ya’ni dinamik yo‘naltirish) deb ataladi va kompilyatsiya jarayonida dastur o‘zi
256256
ishga tushish vaqtida yo‘naltira oladigan kod yaratiladi.
257257

258-
When we use trait objects, Rust must use dynamic dispatch. The compiler doesn’t
259-
know all the types that might be used with the code that’s using trait objects,
260-
so it doesn’t know which method implemented on which type to call. Instead, at
261-
runtime, Rust uses the pointers inside the trait object to know which method to
262-
call. This lookup incurs a runtime cost that doesn’t occur with static
263-
dispatch. Dynamic dispatch also prevents the compiler from choosing to inline a
264-
method’s code, which in turn prevents some optimizations. However, we did get
265-
extra flexibility in the code that we wrote in Listing 17-5 and were able to
266-
support in Listing 17-9, so it’s a trade-off to consider.
258+
Rust-da trait obyektlaridan foydalanganda, dinamik dispatch ishlatiladi.
259+
Kompilyator kodda qaysi turdagi qiymatlar ishlatilishini oldindan bilmaydi,
260+
shuning uchun qaysi turdagi metod chaqirilishini ham bilmaydi. Buning o‘rniga,
261+
bajarilish vaqtida (runtime) Rust trait obyektining ichidagi ko‘rsatkichlardan
262+
(pointer) qaysi metodni chaqirish kerakligini aniqlaydi. Bu esa statik dispatchiga
263+
nisbatan bajarilish vaqtida qo‘shimcha xarajatlarni keltirib chiqaradi. Shuningdek,
264+
dinamik dispatchi kompilyatorga metod kodini inline qilish imkonini bermaydi, bu esa
265+
ba’zi optimallashtirishlarni cheklaydi. Biroq, biz ro‘yxat 17-5 yozgan kodimizda
266+
qo‘shimcha moslashuvchanlikka ega bo‘ldik va ro‘yxat 17-9 da qo‘llab-quvvatlay oldik,
267+
shuning uchun buni hisobga olish kerak.
267268

268269
[performance-of-code-using-generics]: ch10-01-syntax.html#generiklar-yordamida-kodning-ishlashi
269270
[dynamically-sized]: ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait

0 commit comments

Comments
 (0)