Rust Generics and Traits: Define Common Struct Behaviors 🦀

preview_player
Показать описание
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.

Please follow me on these other social channels!

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
Рекомендации по теме
Комментарии
Автор

You present very well I must say. Thanks for making these videos.

wasabinator
Автор

You way of explaining complex stuff is amazing! Thank you! Subscribed!

sval
Автор

Excellent, great clear explanation -> Thank You!

jasonbraithwaite
Автор

thank you so much, you really helped me a lot!

mykolagogol
Автор

Great Stuff!!! Please keep on creating valuable content about Rust. Also, if you please create a video on efficient data structures in Rust.

AM-hcvo
Автор

Such a clear explanation. I like that you didn't just us <T> This video deserves a lot more views. YouTube, sort your algorithm!!

lordmelbury
Автор

One of the best explanations on traits out there! Thank you, Trevor!

eltonrr
Автор

Thank you so much! This was really great and helpful!

moose
Автор

You really nailed the explanation Sir.

aar
Автор

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.

scottb
Автор

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?

skull_cyber
Автор

Hello, sorry I still don't understand traits

why can't we use the below code?

struct Pet<T> {
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?

a_maxed_out_handle_of__chars
Автор

Good sir you missed the implementation on the 'Person' animal.

azystar
Автор

is there a github repo for the code examples ?

bothwellw
Автор

Hey Trevor, so what would YOU use Rust to create? I am asking most ambitious software you can imagine using it for.

princemarkied
Автор

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.

abbcc