Great stuff (as always)! We need more people making videos like this with Rust. I'd love to see videos on: - Using Microsoft's "windows" crate - Associated types - Cross compiling (when can you just specify a different target to cargo vs need to use something like rust-musl-builder) - The Typestate Pattern / why ownership is great for more than just memory safety
I think this is pitched perfectly, logically guiding the viewer through the concept in accessible steps. I loved the proof via assembly! I'm really enjoying your content, Ryan, keep up the good work. And thank you!
Really awesome work, loved the debugging of the generated ASM. I have been using dynamic dispatch for the most part without even realizing it. Will definitively be on the lookout to use static dispatch wherever I can. Thanks for the video
Thanks much for sharing these. Definitely helping. Wanted to suggest a few future topics if you're ever looking for some. Two for me would be use cases for using Cow, and a discussion of use cases for functionality in "std::mem" which seems to get used a lot but not discussed a lot, or minimally discussed.
Ryan, thank you for this youtube you created; you make me think about programming through rust and your explanation more thoroughly than before. I believe rust is better be used for blockchain.
Really great stuff, for a beginner like me it now finally "klicked" about all the dyn, Box and trait business. Monomorphisation, didn't know assembly macros and C++ templates had a word :D Also need to delve in that gdb stuff, looks interesting. And of course Ryan you're a sympathetic guy and I like that deep voice, in addition to the skills and knowledge :D
2 questions, can a function return a dynamic dispatched type, ex: `Box`, And does this make us able to return different concrete spellcheckers at different places in the function?
Spellcheck is actually one word. On account of that, it should only be capitalized at the beginning. Whenever we used snake case or camel case, it was always to separate different words, however spellcheck is completely 1 word only. So says the dictionary. So that should solve the debate on whether to capitalize the C or not Edit: Also just discovered you're on the "Edition 2021 Project Group". Cool!
The only thing that really confused me was using the struct name as an argument. I kept asking myself, if that would be an i32, you would be passing a for example a "5" and not a "i32" right. So if I'm not mistaken, it is called a "union struct", and while it was passed as an argument, it was interpreted not as a "type" but as a than and there created new struct object (or how to call it) that didn't need a body there, since it's a union struct. Normally, if it would have a body, I assume you would also pass it as a reference, to not destroy it in the process.
Almost. It's called a unit struct or unit-like struct. A union is something else. Actually, the explanation is simpler than that. Take an ordinary struct: `struct Something { inner: u32 }`. You could use "struct literal syntax" to construct it, by writing `let something = Something { inner: 42 };`. A tuple struct is largely the same: `struct Something(u32);`. Side note: this is effectively the same type as the above, but with unnamed fields. You could use struct literal syntax to construct it in a similar way, by writing `let something = Something(42);`. Now, a unit struct has no fields: `struct Something;`. How would you construct it using struct literal syntax? That's right: `let something = Something;`. So in the video, a new value is constructed and immediately passed (by value or by reference) into each of the spellcheck functions.
Box is not a heap allocated pointer. Box is a stack allocated pointer that points to heap allocated memory which contains that object we are pointing too.
This is correct. "Heap allocated pointer" was a poor way to phrase it, but yes, I meant "pointer to heap allocated data". Sorry for the poor choice of words!
@@RyanLevicksVideos Np, I understand, working live, etc, everyone can make mistake. It is important though to clear those after, so people who watch it get the correct picture. Anyway, great video, keep up the good work!
@@Tigregalis Only first Box is on the stack. Rest is on the heap. The point here is that the size of object which is passed to a function as an argument must be known at compile time (because of the way compilers/hardware works)
Hello Ryan. For MS VS Code - which extensions do you recommend to install for Rust full-cycle development and debugging?? Please Include code, debug and build extensions please, for both Windows 10 and for Linux (if any difference). Alternatively, if there is a video covering this topic, please supply a pointer to it? Thank you very much.
Any chance you could...uhm...do a small intro/tut for opengl with rust? I have a c++ gui here I would very much like to port to rust...but the gl stuff ive seen seems weird. And thats not even considering the gui and how to handle some stuff, for example, my widgets live in folder components, which in turn live in cells - Each cell can have 2 children(pointers). How would that work in rust??
Does monomorphization occur for each type it finds that implements a trait regardless of whether or not it actually is ever used in a call, or is it only compiled in if it's actually used in a call? Like if there are 100 spellcheckers in some included crate, but only 3 get used in this app, does it compile 3 functions or 100 ?
What do you mean by compile? Compiler of course processes all of the code, but monomorphization occurs only for the types that are actually used. Similarly, functions that are not used are also not compiled into the final executable.
Can't the compiler some times these days even reason about some simple virtual functions too, meaning even some virtual function calls can be inlined, or am I missing something, or is that just in C++? I know virtual functions generally come with a cost, but if I am not mistaken, that if the compiler can see through everything, it will inline it (although one should always assume it doesn't)?
impl, as Noir mentioned in his first sentence, does static dispatch. It is the same as the spellcheck1... that was written by Ryan in the presentation - just less syntax sugar (in this case, if you have more complex trait bounds you'll probably prefer using generic type parameters and the where clause = the 3rd option for declaring the same ;)).
Hmm I have VSC with rust-anaylzer but the parameter type hints aren't being displayed like in your video. It looks like you can call a function by typing `foo(a,b)` and your editor will automagically display `foo(a: A, b :B)` where the `:A` and `:B` are in gray? In my rust-analyzer settings it has Parameter Hints and Type Hints both enabled :/ Is it a VSC setting or another plugin maybe?
@@carcass09 Nope my setup is pretty plain. Make sure that rust-analyzer is running and is not erroring (it does a poor job of showing when things go wrong).
41:59 Completely wrong explanation... The vector is a homogeneous container, which can store only objects of the same type "by design". This has nothing to do with different sizes of those objects. Even if you have number of objects with the same size, you still won't be able to make vector out of them. It is simply not how it works.
This is amazing. I was so confused about the generics and the dynamic vs static dispatch. This drove the point home for me. I feel like I really understand it now. Thanks so much for streaming this.
You said "umm" / "uuugh" 26 times in the first 2 minutes. Don't let this easy and common mistake take away from your work or intelligence. Stop saying "umm"!
Showing the difference between dynamic and static dispatch in assembly was super cool and helpful. Great stream!
i know Im quite off topic but does anybody know of a good place to watch newly released tv shows online?
@William Roberto I watch on Flixzone. You can find it on google =)
@@bakerzain4877
Is this a bot scam ?
@@xrafter probably
Ryan is a true teacher ...this man really knows how to explain great things , Ryan the Boss.
hey long time, we need more rustttttttttttttttt
Great stuff (as always)! We need more people making videos like this with Rust.
I'd love to see videos on:
- Using Microsoft's "windows" crate
- Associated types
- Cross compiling (when can you just specify a different target to cargo vs need to use something like rust-musl-builder)
- The Typestate Pattern / why ownership is great for more than just memory safety
I think this is pitched perfectly, logically guiding the viewer through the concept in accessible steps.
I loved the proof via assembly!
I'm really enjoying your content, Ryan, keep up the good work. And thank you!
One of the few channels in TH-cam to cater to intermediate level developers. Thanks a lot for this great content :D
Really awesome work, loved the debugging of the generated ASM. I have been using dynamic dispatch for the most part without even realizing it. Will definitively be on the lookout to use static dispatch wherever I can. Thanks for the video
Thanks much for sharing these. Definitely helping. Wanted to suggest a few future topics if you're ever looking for some. Two for me would be use cases for using Cow, and a discussion of use cases for functionality in "std::mem" which seems to get used a lot but not discussed a lot, or minimally discussed.
Wow, this really made me understand Static dispatch/Dynamic Dispatch. Thank you so much!.
Awesome stream and one of the best rust content i've ever seen. ♥️
your tutorials are borderline flawless man. thank you for your efforts and keep it coming :)
Presentation was on 🔥! Thanks! 👋🏼👍🏼
Great content. I'd love it if you could go further into trait objects, in particular dyn Any, downcasting, and using dyn Any with other traits.
Ryan, thank you for this youtube you created; you make me think about programming through rust and your explanation more thoroughly than before. I believe rust is better be used for blockchain.
Very informative and helpful for learning the concept. Thanks a lot.
Box vs &dyn was exactly what I came here to discover 👍
Well explained and just the right amount of depth.
Really great stuff, for a beginner like me it now finally "klicked" about all the dyn, Box and trait business. Monomorphisation, didn't know assembly macros and C++ templates had a word :D
Also need to delve in that gdb stuff, looks interesting.
And of course Ryan you're a sympathetic guy and I like that deep voice, in addition to the skills and knowledge :D
it is a shame that this channel is not uploading more content, really really nice.
Thanks Ryan. Excellent resource, I've learned a lot.
Great content. You are doing good. Will definitely come back for the next. Thumbs Up 👍
2 questions, can a function return a dynamic dispatched type, ex: `Box`,
And does this make us able to return different concrete spellcheckers at different places in the function?
Short answer: yes and yes
Spellcheck is actually one word. On account of that, it should only be capitalized at the beginning. Whenever we used snake case or camel case, it was always to separate different words, however spellcheck is completely 1 word only. So says the dictionary. So that should solve the debate on whether to capitalize the C or not
Edit: Also just discovered you're on the "Edition 2021 Project Group". Cool!
The only thing that really confused me was using the struct name as an argument. I kept asking myself, if that would be an i32, you would be passing a for example a "5" and not a "i32" right. So if I'm not mistaken, it is called a "union struct", and while it was passed as an argument, it was interpreted not as a "type" but as a than and there created new struct object (or how to call it) that didn't need a body there, since it's a union struct. Normally, if it would have a body, I assume you would also pass it as a reference, to not destroy it in the process.
Almost. It's called a unit struct or unit-like struct. A union is something else.
Actually, the explanation is simpler than that.
Take an ordinary struct: `struct Something { inner: u32 }`. You could use "struct literal syntax" to construct it, by writing `let something = Something { inner: 42 };`.
A tuple struct is largely the same: `struct Something(u32);`. Side note: this is effectively the same type as the above, but with unnamed fields. You could use struct literal syntax to construct it in a similar way, by writing `let something = Something(42);`.
Now, a unit struct has no fields: `struct Something;`. How would you construct it using struct literal syntax? That's right: `let something = Something;`. So in the video, a new value is constructed and immediately passed (by value or by reference) into each of the spellcheck functions.
@@Tigregalis Thank you so much for the explanation! I was confused too!
Could you make a list of keyboard shortcuts that you do during the video? Thanks for the video!
Box is not a heap allocated pointer. Box is a stack allocated pointer that points to heap allocated memory which contains that object we are pointing too.
This is correct. "Heap allocated pointer" was a poor way to phrase it, but yes, I meant "pointer to heap allocated data". Sorry for the poor choice of words!
@@RyanLevicksVideos Np, I understand, working live, etc, everyone can make mistake. It is important though to clear those after, so people who watch it get the correct picture. Anyway, great video, keep up the good work!
what if it's a Box?
@@Tigregalis yes then it's a heap allocated pointer 😊 words are hard.
@@Tigregalis Only first Box is on the stack. Rest is on the heap. The point here is that the size of object which is passed to a function as an argument must be known at compile time (because of the way compilers/hardware works)
These videos are really really helpful. Thank you.
Hello Ryan. For MS VS Code - which extensions do you recommend to install for Rust full-cycle development and debugging?? Please Include code, debug and build extensions please, for both Windows 10 and for Linux (if any difference). Alternatively, if there is a video covering this topic, please supply a pointer to it? Thank you very much.
Any chance you could...uhm...do a small intro/tut for opengl with rust?
I have a c++ gui here I would very much like to port to rust...but the gl stuff ive seen seems weird.
And thats not even considering the gui and how to handle some stuff, for example, my widgets live in folder components, which in turn live in cells - Each cell can have 2 children(pointers). How would that work in rust??
Thank you! Perfect pace
Ok, I'm ready to melt down my brain. Lets do this!
Does monomorphization occur for each type it finds that implements a trait regardless of whether or not it actually is ever used in a call, or is it only compiled in if it's actually used in a call? Like if there are 100 spellcheckers in some included crate, but only 3 get used in this app, does it compile 3 functions or 100 ?
What do you mean by compile? Compiler of course processes all of the code, but monomorphization occurs only for the types that are actually used. Similarly, functions that are not used are also not compiled into the final executable.
@@bostjanvesnicer - Thanks, that's what I was after - that it only compiles for types that are used. That's good to hear.
Can't the compiler some times these days even reason about some simple virtual functions too, meaning even some virtual function calls can be inlined, or am I missing something, or is that just in C++? I know virtual functions generally come with a cost, but if I am not mistaken, that if the compiler can see through everything, it will inline it (although one should always assume it doesn't)?
Thank you. Your explain make it very clear and straightforward for me
Is this channel dead? No updates in a year and a half? Where's the new videos?
This is amazing!!! Thanks :D
Very effective as always.
very educative, thank you!
thanks Ryan
I think dyn is said as 'dine' as in short for the word dynamic
In my head I keep reading it like "din" in dinner. Probably depends on your mother tongue.
Amazing video! Thanks!
awesome! easy to understand.
30:30 what if you write 'impl Spellchecker' instead of dyn?
But what was the title during the stream!
Amazing video. Thank you.
Great content. Thanks for sharing.
Thanks for the awesome content!
Keep up the great work!
loved this thanks
Thank you 😊
Great video thanks
i guess there must be a difference between dyn keyword and impl mentioned by Noir?
impl, as Noir mentioned in his first sentence, does static dispatch. It is the same as the spellcheck1... that was written by Ryan in the presentation - just less syntax sugar (in this case, if you have more complex trait bounds you'll probably prefer using generic type parameters and the where clause = the 3rd option for declaring the same ;)).
Minute 20: why can you just pass a type to the spellcheck function in the test without instantiating an object first?
man pls make more videos...
Great explanation…
What's the VSCode plug-in to automatically display type annotations?
and parameter names?
I use the rust-analyzer plug-in which is definitely the recommended plug-in as it will become the official plug-in in the future.
@@RyanLevicksVideos Cheers! Thanks for the great vids:D
Hmm I have VSC with rust-anaylzer but the parameter type hints aren't being displayed like in your video. It looks like you can call a function by typing `foo(a,b)` and your editor will automagically display `foo(a: A, b :B)` where the `:A` and `:B` are in gray? In my rust-analyzer settings it has Parameter Hints and Type Hints both enabled :/ Is it a VSC setting or another plugin maybe?
@@carcass09 Nope my setup is pretty plain. Make sure that rust-analyzer is running and is not erroring (it does a poor job of showing when things go wrong).
10:25 Good one. Maybe you should ask spellchecker how to spell it?
That thumbnail tho :D
@@MatthewHolevinski I thought it said Ryanamic at first glance.
@@joachimm81 my brain broke and I legit had no idea what it said
thankyougreatvideowillalwaysuseantispacecheckerfromnowon
41:59 Completely wrong explanation... The vector is a homogeneous container, which can store only objects of the same type "by design". This has nothing to do with different sizes of those objects. Even if you have number of objects with the same size, you still won't be able to make vector out of them. It is simply not how it works.
why stop making videos?
You have a typo in your code ;P :P ;P
This is amazing. I was so confused about the generics and the dynamic vs static dispatch. This drove the point home for me. I feel like I really understand it now. Thanks so much for streaming this.
Cent you just say
Let spellcheckers = vec![spellchecker] .....
Mhmmm
Rust red hair 👩🏾🦰 huh
You said "umm" / "uuugh" 26 times in the first 2 minutes. Don't let this easy and common mistake take away from your work or intelligence. Stop saying "umm"!