Using Trait Objects in Rust

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

Chapters:
0:00​ Intro
00:37 Trait for Common Behavior
5:45 Implementing the Trait
10:46 Static vs Dynamic Dispatch
12:23 Object Safety for Trait Objects
13:03 Outro

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

Man, it's amazing how easily you make it seem like concepts I couldn't understand. Thanks for your work!!

nko
Автор

For newbies and people from other languages it might be helpful to say that traits are similar to interfaces in other languages like C# and Java - without the field stuff as you noted.
Traits inverse the control - in other languages you define the interfaces first, then let types (classes) inherit them - in Rust you can arbitrarily define and use traits for existing objects (structs) even if you don't have access to the source code.

TechLord
Автор

I read the first half of the Rust book. then I found this channel. Watching these videos is way easier to learn Rust with than reading that big book lol. I can just sit back and learn.

ZoroastrianCowboy
Автор

This is such a timely video for me. Really appreciate you explaining why generics aren’t always appropriate solution 👍

markmcdonnell
Автор

I hope more people will subscribe. You're creating the best teaching material for Rust! Thanks a lot!

ZigzauerLT
Автор

Needed this, thanks! I rave about you and I pray that others watch you content too.

ShreksSpliff
Автор

So glad I found this. I've been breathing my head against a wall trying to use egui and it's spotty docs

brandonmint
Автор

I'm so glad the first language I learnt was C++ (although, that was 6 years ago). A lot of these concepts I kind of know, just rusty :D

jobrown
Автор

Should make a series going through the traits in the standard library. Would be helpful

davidk.
Автор

Great video thank you, that's just what I needed to understand

arturkarabekov
Автор

у вас дуже гарний і корисний канал, дякую.

spiritofage
Автор

Man, i just want to see your channel succeed :(

iflbzyi
Автор

excellent as always, waiting for the cheatsheet

herrxerex
Автор

Pretty much same as Golang. Passing interfaces in function argument does the same thing in Golang too. Its a runtime check by go runtime to figure out which object it is vs the generic static dispatch. So, Generic faster than Traits objects, but trait objects have more flexibiltiy in writing clean code

fewgfwe
Автор

Love the video. I have one question :
So in the case of dynamic dispatch, the rust compiler does some computation at runtime and hence we have a runtime cost. But how is a compiler working at runtime? I used to think the compiler after compiling the code is done with its duty and after that runtime libraries do all the remaining stuff?

amoghyermalkar
Автор

Great video. After watching the video I feel more comfortable with trait objects. But I am not able to find RFC for "object safe" as mentioned by you in the video. Am I missing something.

adityapoddar
Автор

Nice explanation. Still wondering why Box() is needed around the different objects though, I know it has something to do with them being of different types, but still not sure why this further level of abstraction is needed.

mutantthegreat
Автор

Can you use `Vec<&dyn Draw>` instead of `Vec<Box<dyn Draw>>`?

khandarwilliam
Автор

Nice, I remember a comment I made on one of your videos about this!

inx
Автор

what's the addon you're using for auto complete suggestions?

leftspace