Тёмный

Rust Generics and Traits: Define Common Struct Behaviors 🦀 

Trevor Sullivan
Подписаться 17 тыс.
Просмотров 6 тыс.
50% 1

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@TrevorSullivan
@TrevorSullivan Год назад
Check out the FULL Rust video playlist! 🦀 ru-vid.com/group/PLDbRgZ0OOEpUkWDGqp91ODn0dk7LPBAUL
@wasabinator
@wasabinator 16 дней назад
You present very well I must say. Thanks for making these videos.
@sval4020
@sval4020 6 месяцев назад
You way of explaining complex stuff is amazing! Thank you! Subscribed!
@TrevorSullivan
@TrevorSullivan 6 месяцев назад
You're so kind! Thank you and I'm glad you're learning! 🥰🦀
@jasonbraithwaite9204
@jasonbraithwaite9204 4 месяца назад
Excellent, great clear explanation -> Thank You!
@Esmairidem
@Esmairidem 4 дня назад
Great explanation, thanks bro
@mykolagogol1192
@mykolagogol1192 2 месяца назад
thank you so much, you really helped me a lot!
@AM-hc5vo
@AM-hc5vo 4 месяца назад
Great Stuff!!! Please keep on creating valuable content about Rust. Also, if you please create a video on efficient data structures in Rust.
@eltonrr1
@eltonrr1 Год назад
One of the best explanations on traits out there! Thank you, Trevor!
@lordmelbury7174
@lordmelbury7174 8 месяцев назад
Such a clear explanation. I like that you didn't just us This video deserves a lot more views. RU-vid, sort your algorithm!!
@TrevorSullivan
@TrevorSullivan 8 месяцев назад
Thanks so much for your kind feedback! I'm glad you got something out of this video!
@moose304
@moose304 10 месяцев назад
Thank you so much! This was really great and helpful!
@rasi_rawss
@rasi_rawss Месяц назад
Superb!
@alishmod530
@alishmod530 5 месяцев назад
Awsome teaching
@Andrew_.
@Andrew_. 11 месяцев назад
thanks a lot for your work mate !❤
@gautamjh
@gautamjh 8 месяцев назад
Great Exaplanation!
@skull_cyber
@skull_cyber 5 месяцев назад
Im confuse in rust concepts from enums to everyother. Your videos are great when i try to implement these on my side it gets hard. can you tell me some exercises which helps me clearing concepts in rust about each topic?
@TrevorSullivan
@TrevorSullivan 5 месяцев назад
Hello thanks for sharing your experience with Rust. I would recommend taking what you learn in these videos and adapt it to a different use case. For example, if I use an animal as an example, change it to a vehicle instead. Or a plane with departure / arrival times and locations, or a train that has a schedule. Make sense? Just think of something in the real world and then try to model it using Rust structs and methods.
@nhwhn
@nhwhn 7 месяцев назад
awesome video
@aar021
@aar021 Год назад
You really nailed the explanation Sir.
@ExidifulCrypto
@ExidifulCrypto 11 месяцев назад
Thanks a lot mate, u r the best
@TrevorSullivan
@TrevorSullivan 11 месяцев назад
I'm glad you're learning Rust!! 🦀
@kurkdebraine8139
@kurkdebraine8139 5 месяцев назад
Great !
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 10 месяцев назад
Hello, sorry I still don't understand traits why can't we use the below code? struct Pet { first_name: String, pet: T, } struct Dog {} impl Dog { fn make_sound(self) { println!("bark!"); } } struct Cat {} impl Cat { fn make_sound(self) { println!("meow!"); } } fn main() { let dog1 = Dog {}; let cat1 = Cat {}; let p1 = Pet { first_name: "dog".to_string(), pet: dog1, }; let p2 = Pet { first_name: "cat".to_string(), pet: cat1, }; p1.pet.make_sound(); p2.pet.make_sound(); } why do we need traits when using implementation block works?
@TrevorSullivan
@TrevorSullivan 10 месяцев назад
That's a great question! Generics and Traits offer some similar functionality. However, the benefit with traits is that you can focus on object behaviors rather than the types themselves. In your example, a crocodile also makes a sound, but a crocodile is not a pet. So if you need to access common behavior across dogs, cats, and crocodiles, using the Pet type doesn't make sense, because crocodiles aren't pets. Instead, you would define a trait called "MakesSound" (or whatever name you want) and then declare the make_sound() function in that trait. There's nothing wrong with using generics, as long as they fit your use case. Traits just give you another mechanism to deal with different types. I hope this helps!!
@scottb4029
@scottb4029 10 месяцев назад
Trevor, could you implement an enum as a trait for the pets and have the enum have all of the pets? Also, I wanted to say, thank you. This might be the best video on traits and generics I have ever seen.
@TrevorSullivan
@TrevorSullivan 10 месяцев назад
Thank you! I'm so glad that this series has helped you. Could you share a code example of what you're thinking?
@scottb4029
@scottb4029 10 месяцев назад
​​@@TrevorSullivanenum PetType{Dog, Cat,Bear,Tiger} as the selection for your pet "type"?
@gokulrashtrami4340
@gokulrashtrami4340 Год назад
Best explanation dude!!
@abbcc555
@abbcc555 11 месяцев назад
This really solidified my understanding. By far the best explanation. Your examples and pace is perfect, also the fact that you didn't conform to the typical(pun intended) use of T and U etc.
@MH-bw9lh
@MH-bw9lh Год назад
❤❤❤❤
@azystar4563
@azystar4563 7 месяцев назад
Good sir you missed the implementation on the 'Person' animal.
@princemarkied8071
@princemarkied8071 Год назад
Hey Trevor, so what would YOU use Rust to create? I am asking most ambitious software you can imagine using it for.
@TrevorSullivan
@TrevorSullivan Год назад
Most ambitious? I'm not sure about that, but for starters, think about some CLI tools you could use. What about building web APIs, to call from automation scripts? For example, a TUI (Terminal User Interface) that helps you manage Kubernetes clusters, maybe? What kinds of technologies do you work with, and what could you simplify?
@TrevorSullivan
@TrevorSullivan Год назад
Benchmarking tools would be another great use case for Rust, since it's a high performance language. For example, build a Postgres or MySQL benchmarking tool to compare performance in different configurations.
@bothwellw
@bothwellw 5 месяцев назад
is there a github repo for the code examples ?
@TrevorSullivan
@TrevorSullivan 5 месяцев назад
@bothwellw Unfortunately no, I don't have a GitHub repository for the samples. I encourage people to write the code out for themselves, to learn how things work. It's good exercise.
@ojoawojoshua780
@ojoawojoshua780 2 месяца назад
But some dogs are dangerous 😭
Далее
Rust Powered Polymorphism ⚡️ With Traits
9:55
Просмотров 99 тыс.
Intro to Developing User-Defined Rust Structs 🦀
41:40
Implement Methods on Rust Structs 🦀
27:27
Просмотров 5 тыс.
Rust: Generics, Traits, Lifetimes
35:34
Просмотров 48 тыс.
All Rust string types explained
22:13
Просмотров 172 тыс.
Rust Generics
22:10
Просмотров 21 тыс.
Rust's second most complicated feature explained
7:48
Two Ways To Do Dynamic Dispatch
19:54
Просмотров 75 тыс.