Тёмный

Rust Generics and Traits: Define Common Struct Behaviors 🦀 

Trevor Sullivan
Подписаться 14 тыс.
Просмотров 3,9 тыс.
50% 1

The Rust language provides a couple of important concepts called Traits and Generics. These two constructs work closely in conjunction with each other, to reduce the amount of code that's necessary to write software effectively. In this video, we will explore how Traits are defined, how to define Generic input arguments on Rust structs, and how to use Trait Bounds to limit which types can be used as Generic inputs.
🤯 Rust Programming Playlist 🦀 • Rust Programming Tutor...
📖 Rust Traits: doc.rust-lang.org/book/ch10-0...
📖 Rust Generics: doc.rust-lang.org/book/ch10-0...
Visual Studio Code ➡️ code.visualstudio.com
Rust Website ➡️ rust-lang.org
Rustup Installer ➡️ rustup.rs
Rust Docs ➡️ doc.rust-lang.org/book
Please follow me on these other social channels!
➡️ trevorsullivan.net
➡️ github.com/pcgeek86
➡️ / pcgeek86
➡️ / trevorsullivan
➡️ / trevorsoftware
➡️ tiktok.com/pcgeek86
All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.
#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer

Наука

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

 

16 июн 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@TrevorSullivan
@TrevorSullivan 9 месяцев назад
Check out the FULL Rust video playlist! 🦀 ru-vid.com/group/PLDbRgZ0OOEpUkWDGqp91ODn0dk7LPBAUL
@eltonrr1
@eltonrr1 9 месяцев назад
One of the best explanations on traits out there! Thank you, Trevor!
@abbcc555
@abbcc555 8 месяцев назад
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.
@jasonbraithwaite9204
@jasonbraithwaite9204 25 дней назад
Excellent, great clear explanation -> Thank You!
@moose304
@moose304 6 месяцев назад
Thank you so much! This was really great and helpful!
@aar021
@aar021 8 месяцев назад
You really nailed the explanation Sir.
@gokulrashtrami4340
@gokulrashtrami4340 8 месяцев назад
Best explanation dude!!
@Andrew_.
@Andrew_. 8 месяцев назад
thanks a lot for your work mate !❤
@sval4020
@sval4020 2 месяца назад
You way of explaining complex stuff is amazing! Thank you! Subscribed!
@TrevorSullivan
@TrevorSullivan 2 месяца назад
You're so kind! Thank you and I'm glad you're learning! 🥰🦀
@gautamjh
@gautamjh 4 месяца назад
Great Exaplanation!
@alishmod530
@alishmod530 Месяц назад
Awsome teaching
@nhwhn
@nhwhn 3 месяца назад
awesome video
@AM-hc5vo
@AM-hc5vo Месяц назад
Great Stuff!!! Please keep on creating valuable content about Rust. Also, if you please create a video on efficient data structures in Rust.
@ExidifulCrypto
@ExidifulCrypto 8 месяцев назад
Thanks a lot mate, u r the best
@TrevorSullivan
@TrevorSullivan 8 месяцев назад
I'm glad you're learning Rust!! 🦀
@kurkdebraine8139
@kurkdebraine8139 2 месяца назад
Great !
@scottb4029
@scottb4029 7 месяцев назад
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 7 месяцев назад
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 7 месяцев назад
​​@@TrevorSullivanenum PetType{Dog, Cat,Bear,Tiger} as the selection for your pet "type"?
@azystar4563
@azystar4563 3 месяца назад
Good sir you missed the implementation on the 'Person' animal.
@cybertache
@cybertache 2 месяца назад
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 2 месяца назад
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.
@lordmelbury7174
@lordmelbury7174 5 месяцев назад
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 5 месяцев назад
Thanks so much for your kind feedback! I'm glad you got something out of this video!
@MH-bw9lh
@MH-bw9lh 9 месяцев назад
❤❤❤❤
@bothwellw
@bothwellw Месяц назад
is there a github repo for the code examples ?
@TrevorSullivan
@TrevorSullivan Месяц назад
@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.
@princemarkied8071
@princemarkied8071 9 месяцев назад
Hey Trevor, so what would YOU use Rust to create? I am asking most ambitious software you can imagine using it for.
@TrevorSullivan
@TrevorSullivan 9 месяцев назад
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 9 месяцев назад
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.
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 7 месяцев назад
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 7 месяцев назад
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!!
Далее
Popular Rust Iterator Methods 🦀
54:54
Просмотров 5 тыс.
Редакция. News: 121-я неделя
42:58
Просмотров 1,2 млн
Fudbol hozir vs avval😂
01:01
Просмотров 478 тыс.
Rust Threading Basics 🦀 Rust Tutorial
28:26
Просмотров 4,4 тыс.
Share Rust Thread Data With Mutexes 🦀 Rust Tutorial
35:36
Stefan Baumgartner - Trials, Traits, and Tribulations
28:15
You Should Really Know These Traits in Rust
18:36
Просмотров 10 тыс.
Rust Structs, Traits and Impl
24:53
Просмотров 33 тыс.
Constructors Are Broken
18:16
Просмотров 100 тыс.
Rust Powered Polymorphism ⚡️ With Traits
9:55
Просмотров 90 тыс.
TOP-18 ФИШЕК iOS 18
17:09
Просмотров 721 тыс.
НАШ ЛЮБИМЫЙ КЛИЕНТ
1:00
Просмотров 512 тыс.
wireless switch without wires part 6
0:49
Просмотров 3,9 млн
wireless switch without wires part 6
0:49
Просмотров 3,9 млн
Face ID iPhone 14 Pro
0:59
Просмотров 14 тыс.
Bardak ile Projektör Nasıl Yapılır?
0:19
Просмотров 6 млн