21:10 putting constraints at "struct" block level forces every "impl" blocks to apply these constraints but does not automatically apply them to "impl" blocks. This is more explicit this way and also allow "impl" blocks to apply more constraints than those specified on "struct" blocks.
This definitely is one of those moment where the Rust compiler seems more autistic than it needs to be, but it makes sense once you realize Rust is always trying to keep relevant things together. Want to use a method in the implementation? It better be in the constraints of the implementation, and not somewhere else! (Even if that "somewhere else" is in the struct that the impl is implementing).
What a beast! Saw 3 other channels but they would not address why we need to define generic type on functions. This did not only do that but went out of the way for ins and outs! Dayum! 🙌🙌
Coming from the JS battlefield, I had quite a hard time wrapping my head around all these concepts. You're doing a great job explaining them, thank you very much!
From your previous comment on the Structs and Traits video you had asked if I could make a Generics video. I was going to tell you that the Generics video you requested was up, but you beat me to the punch! Ha, ha, ha... I'm glad you're enjoying them.
I finally got it!, I literally said Holy sh*t. You program to the trait unlocked generics for me, I was working backwards. The other statement that was an epiphany for me was "Lifetimes, it's all about the references. " THANKS SO MUCH !!
Your tutorials on Rust are so good that I click thumbs up before I watch the episode. ;) I'm really surprised you have got so little views here, that a shame
Thanks for this tutorial, I managed to get it after watching it twice but I think it'd be easier to grasp if you used real world examples instead of arbitrary Struct, field and variable names like DougStruct, dougs_t, dougs_func etc. Sort of like what you did in the enum tutorial with the payment types, that me it way easier. Thanks again.
Thanks for the informative video(s)! I especially enjoyed the Browser 3D series. As for the last point, with being required to put where on the function, my guess is that the thought is to decouple the methods from the data. You could potentially make a number of methods on DougsStruct, and instantiate many different types of T, U of it, and it'd be allowed as long as you don't actually use the log_something method. That's when the constraint kicks in.
Yeah, it looks like you're correct. You can put the where clause on each method as well, not just on the impl block. When I do that, the compiler is smart enough to only give a compile error if I call specific methods. Interesting!
Each and every video is awesome ✨...but only thing that i struggle is sequences to watch...if video title in Sequences ....its easy to understand...else...it help a lot myself...to start with rust...thanks🥳
Is there a way to tell the compiler to only allow some types of T to be available? Like in c++ template concept int_only = std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v; //do also for int16_t and int8_t template T add(T a, T b) { return a + b; } int main() { //ERRORRRRR!!! add(5.0f, 10.0f); } And whenever we'd pass a float or other type that is not allowed we'd get a compile error.
You're probably just missing an extension in VS Code. This video goes over the setup. Maybe it'll highlight what's missing. ruclips.net/video/f6tizikEMTk/видео.html
21:10 putting constraints at "struct" block level forces every "impl" blocks to apply these constraints but does not automatically apply them to "impl" blocks. This is more explicit this way and also allow "impl" blocks to apply more constraints than those specified on "struct" blocks.
This definitely is one of those moment where the Rust compiler seems more autistic than it needs to be, but it makes sense once you realize Rust is always trying to keep relevant things together. Want to use a method in the implementation? It better be in the constraints of the implementation, and not somewhere else! (Even if that "somewhere else" is in the struct that the impl is implementing).
What a beast! Saw 3 other channels but they would not address why we need to define generic type on functions. This did not only do that but went out of the way for ins and outs! Dayum! 🙌🙌
best video explaining generic type in 30 minutes
Ah, thanks!
Coming from the JS battlefield, I had quite a hard time wrapping my head around all these concepts. You're doing a great job explaining them, thank you very much!
Hey, I appreciate the compliment :)
I wish you could make more advanced Rust videos, like error handling and testing! 🙏🏼🙌🏻
Thanks Doug for your fantastic courses! Keep it coming. Very helpful to me.
From your previous comment on the Structs and Traits video you had asked if I could make a Generics video. I was going to tell you that the Generics video you requested was up, but you beat me to the punch! Ha, ha, ha... I'm glad you're enjoying them.
I finally got it!, I literally said Holy sh*t. You program to the trait unlocked generics for me, I was working backwards. The other statement that was an epiphany for me was "Lifetimes, it's all about the references. " THANKS SO MUCH !!
Your tutorials on Rust are so good that I click thumbs up before I watch the episode. ;)
I'm really surprised you have got so little views here, that a shame
Your videos are by far the best ones on Rust and I've watched a lot of them. Thank you, sir 🙏
Fantastic job. I always confused myself with Where clause, type = , what a trait bound means. Now it's clear. Thanks sir.
Doug, your videos are high quality and clear. Thanks for posting!
Thanks Doug . Very helpful to me.❤️👍
Awesome content, great teacher, articulate lessons, great tutorial. The best I have seen so far. Thanks Doug Milford
Thanks Doug, you are a great teacher.
Love your content
I found myself thinking "we haven't covered options yet" for half a minute before I recognize that `OptionA(T)` isn't an `Option(T)` :)
20:14 Using println!("{}", result2); expected "18-first-second", but the result presented was i32-first-second.
Thanks so much for the videos!!!
Thanks for this tutorial, I managed to get it after watching it twice but I think it'd be easier to grasp if you used real world examples instead of arbitrary Struct, field and variable names like DougStruct, dougs_t, dougs_func etc. Sort of like what you did in the enum tutorial with the payment types, that me it way easier. Thanks again.
Yeah, point taken. Often it's easier to learn from real examples. I'll keep that in mind for future videos.
@@dougmilford7814 This is already extremely useful though, thanks.
Doug you're awesome.
Great video!
Doug there are fantastics videos, I hope you're still planning on making these. I would really like to see one on iterators.
One of the best and concise video i've seen so far about generics; Could u also make a video about Lifetimes, thank u very much!
Thanks! I'm currently finishing up the Lifetimes video as we speak. I'm hoping to have it out by the end of this weekend, but no promises.
I published the video on Lifetimes. I hope it helps!
Subscribing your channel today ❤️ Thanks for such awesome clips.
I am expecting some tutorials on diesel queries with postgresql.
Hope.
Thanks for the informative video(s)! I especially enjoyed the Browser 3D series.
As for the last point, with being required to put where on the function, my guess is that the thought is to decouple the methods from the data. You could potentially make a number of methods on DougsStruct, and instantiate many different types of T, U of it, and it'd be allowed as long as you don't actually use the log_something method. That's when the constraint kicks in.
Yeah, it looks like you're correct. You can put the where clause on each method as well, not just on the impl block. When I do that, the compiler is smart enough to only give a compile error if I call specific methods. Interesting!
Thank you so much! Your Rust series is just awesome, clear and concise!
this is gold, thanks!
Each and every video is awesome ✨...but only thing that i struggle is sequences to watch...if video title in
Sequences ....its easy to understand...else...it help a lot myself...to start with rust...thanks🥳
Very helpful 👍 Really Thanks for this.
I request you please make some tutorial on rust with diesel orm . Not understanding diesel.
Thank you so much
Great Video, thanks!
Yep yep, you're welcome :)
You're a god.
7:07 made me laugh harder than it should have.
This is awesome!!!
Hi Doug , can you please start rust coding projects
What if a struct already have a function with the same name as the trait function?
Is there a way to tell the compiler to only allow some types of T to be available? Like in c++
template
concept int_only = std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v; //do also for int16_t and int8_t
template
T add(T a, T b)
{
return a + b;
}
int main()
{
//ERRORRRRR!!!
add(5.0f, 10.0f);
}
And whenever we'd pass a float or other type that is not allowed we'd get a compile error.
excellent video.
Hey, thanks! Glad you liked it :)
Could you make a video on
trait Sometrait {
type Sometype;
}
What if few structs and functions need exactly the same constraints? Is there a way to name, like, 5 constraints and use only 1 name to get them all?
What did you do to have the type appear when you hover your mouse ? This doesn't happen in my VScode.
You're probably just missing an extension in VS Code. This video goes over the setup. Maybe it'll highlight what's missing. ruclips.net/video/f6tizikEMTk/видео.html
doug_func FTW!!!
10:50
14:37 oh no no no... thats absolutely hideous
Wonderful video!
Thank, man! I appreciate the compliment :)