Smart Pointers in Rust - The Deref Trait

preview_player
Показать описание
The ultimate Rust lang tutorial. Follow along as we go through the Rust lang book chapter by chapter.

Chapters:
0:00​ Intro
0:34 Dereference Operator
2:01 Using Box Like a Reference
2:59 Defining Our Own Smart Pointer
4:21 Implementing the Deref Trait
6:40 Implicit Deref Coercions
8:46 Deref Coercion and Mutability
9:38 Outro

#letsgetrusty​​ #rust​lang​ #tutorial
Рекомендации по теме
Комментарии
Автор

Chapter 15 was the first hard "wall" I faced learning Rust. Glad to have these videos to go over and digest the content a bit better.

ChumX
Автор

that was the complete head ache leterally watched 4 times and read the chapter
thanks a lot man

santoshxshrestha
Автор

Difficult concepts become easy because of you! Thank you!

linjianru
Автор

Wow, I was wondering why we can pass &String typed values to the functions that expect &str types, this dereferencing chain explains a lot.

I know that, go also uses a similar approach when it comes to dereferencing, but go compiler is a thousand times worse when making suggestions.

barisballi
Автор

You seriously need to be a CS professor. When I was reading the book I could not wrap my head around Deref but after watching this video everything made sense.

centaurii
Автор

Bogdan, I suggest using "fn new(..) -> Self" default constructor signatures - notice the capital S.
This reduces typing, ensures you don't need to propagate generic types into the output and finally, ensures you automatically propagate changes to generics into the return type (should they change).

mihaigalos
Автор

Thank you for this detailed explanation! As English is not my native language, the word of deref or dereference doesn't make too much sense to me. It sounds for me like the reference is being removed, but it is actually about not performing operations against the reference, but "fetching" the actual value being referenced to perform operations against it right?

scarcalderon
Автор

Holy moly! I write in C++, PL/SQL, Bash, JS, and sometimes PHP every day and I think Rust is really hard. But thankfully we got a wonderful compiler and a teacher like you.

karlheinzneugebauer
Автор

How reference (&) type is calling defef method in mybox @ 8:06, normally deref gets called by *, am I correct, am I missing anything

bjugdbjk
Автор

Hi, please do a series on async rust.

islamibrahim
Автор

If you put an instance of a struct that doesn't implement deref trait into a box then you would not be able to dereference the box right?
If I write
let a = Box::from(MyStruct::new());
I will not be able to write
*a unless MyStruct implements the deref trait, correct?

DipsAndPushups
Автор

I was thinking about this a minute. The deref method of Deref deferences the smart pointer to yield a reference, so it seems to do a double deref in a way as I see it if dereffing the smart pointer yields the same as the integer "value" itself.

fn deref(&self) -> &Self::Target; // see, the reference is returned, not the value

So compiler must be doing some kind of double duty here, apply another deference on the reference returned from deref to get actual underlying value.
idk, something they don't explain well at this point.

Cause if deref returns a reference, how could it equal "5" literal integer value?

jeffg
Автор

Does dereferencing a reference return the original type? Than how borrowing rules apply?
let a = String::new();
let b = &a;
let c=*b; // c is a? Than what happens if i dereference a referenced parameter inside a function? Does it still work with the reference?

denizsincar
Автор

when will the video for asynchronous programming in Rust be ready?

caseyyeow
Автор

Any way you can post twice a week instead of once?

abhinavchavali
Автор

Wish they just made C with borrow checker.

Instead of all these magic

benjaminhon
Автор

📝 Get notified when the Rust Cheatsheet comes out ;)

GolangDojo
Автор

Just wanted to say, can you actually explain the nitty gritty of the topics instead of just reading lines from the rust book

asd-blur
Автор

Also, you can simply do the dot operator "." on types that implement Deref. Like so : x.foo().

In C and C++ you need to use the arrow -> instead.

hermannpaschulke
Автор

if assert_eq!(5, y) doesn't work then why println!("{y}") works?

rishabhagrawalzra
welcome to shbcf.ru