Dynamic vs Static Dispatch in Rust

Поделиться
HTML-код
  • Опубликовано: 2 фев 2025

Комментарии • 93

  • @parthikpatel6108
    @parthikpatel6108 4 года назад +38

    Showing the difference between dynamic and static dispatch in assembly was super cool and helpful. Great stream!

    • @williamroberto6980
      @williamroberto6980 3 года назад +1

      i know Im quite off topic but does anybody know of a good place to watch newly released tv shows online?

    • @bakerzain4877
      @bakerzain4877 3 года назад

      @William Roberto I watch on Flixzone. You can find it on google =)

    • @xrafter
      @xrafter 3 года назад +2

      @@bakerzain4877
      Is this a bot scam ?

    • @ledues3336
      @ledues3336 3 года назад +2

      @@xrafter probably

  • @MrAnandml
    @MrAnandml 3 года назад +5

    Ryan is a true teacher ...this man really knows how to explain great things , Ryan the Boss.

  • @jamie_rides
    @jamie_rides 4 года назад +2

    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!

  • @guidyouguy7306
    @guidyouguy7306 2 года назад +4

    hey long time, we need more rustttttttttttttttt

  • @AndrewBanchich
    @AndrewBanchich 4 года назад +3

    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

  • @joaodiasconde
    @joaodiasconde 4 года назад +1

    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

  • @pandulaweerasooriya7689
    @pandulaweerasooriya7689 3 года назад

    One of the few channels in RUclips to cater to intermediate level developers. Thanks a lot for this great content :D

  • @jashanj0tsingh
    @jashanj0tsingh 3 года назад +1

    your tutorials are borderline flawless man. thank you for your efforts and keep it coming :)

  • @360nickx
    @360nickx 3 года назад +2

    Wow, this really made me understand Static dispatch/Dynamic Dispatch. Thank you so much!.

  • @jeffg4686
    @jeffg4686 4 года назад +1

    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.

  • @numtostr
    @numtostr 4 года назад +4

    Awesome stream and one of the best rust content i've ever seen. ♥️

  • @joelmontesdeoca6572
    @joelmontesdeoca6572 2 года назад +1

    Presentation was on 🔥! Thanks! 👋🏼👍🏼

  • @sffortytwo
    @sffortytwo 2 года назад

    Well explained and just the right amount of depth.

  • @Tigregalis
    @Tigregalis 4 года назад +4

    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.

  • @LeKrul
    @LeKrul 8 месяцев назад

    Thanks Ryan. Excellent resource, I've learned a lot.

  • @arturczajkowski4255
    @arturczajkowski4255 4 года назад +2

    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.

    • @RyanLevicksVideos
      @RyanLevicksVideos  4 года назад +3

      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!

    • @arturczajkowski4255
      @arturczajkowski4255 4 года назад

      @@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
      @Tigregalis 4 года назад

      what if it's a Box?

    • @RyanLevicksVideos
      @RyanLevicksVideos  4 года назад

      @@Tigregalis yes then it's a heap allocated pointer 😊 words are hard.

    • @arturczajkowski4255
      @arturczajkowski4255 4 года назад

      @@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)

  • @markmcdonnell
    @markmcdonnell 2 года назад

    Box vs &dyn was exactly what I came here to discover 👍

  • @haissambadih6773
    @haissambadih6773 2 года назад

    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.

  • @malharvora1281
    @malharvora1281 4 года назад +1

    Very informative and helpful for learning the concept. Thanks a lot.

  • @dabrick100
    @dabrick100 4 года назад +1

    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?

  • @TechLord79
    @TechLord79 3 года назад

    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

  • @AlexeyYunoshev
    @AlexeyYunoshev 2 года назад

    Thank you! Perfect pace

  • @austecon6818
    @austecon6818 3 года назад

    These videos are really really helpful. Thank you.

  • @alexzander__6334
    @alexzander__6334 2 года назад

    30:30 what if you write 'impl Spellchecker' instead of dyn?

  • @sagnikbhattacharya1202
    @sagnikbhattacharya1202 3 года назад +1

    This is amazing!!! Thanks :D

  • @TheNoirKamui
    @TheNoirKamui 4 года назад +2

    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.

    • @Tigregalis
      @Tigregalis 4 года назад +4

      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.

    • @gaastonsr
      @gaastonsr 3 года назад

      @@Tigregalis Thank you so much for the explanation! I was confused too!

  • @patix0331
    @patix0331 4 года назад

    Thank you. Your explain make it very clear and straightforward for me

  • @tomasz-waszczyk
    @tomasz-waszczyk Год назад

    Could you make a list of keyboard shortcuts that you do during the video? Thanks for the video!

  • @noyb-yb
    @noyb-yb 3 года назад

    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.

  • @darkarie
    @darkarie Год назад

    it is a shame that this channel is not uploading more content, really really nice.

  • @simonfarre4907
    @simonfarre4907 3 года назад

    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)?

  • @syntaxed2
    @syntaxed2 3 года назад +1

    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??

  • @amidfallen
    @amidfallen Год назад

    very educative, thank you!

  • @jeffg4686
    @jeffg4686 4 года назад +1

    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 ?

    • @bostjanvesnicer
      @bostjanvesnicer 4 года назад +2

      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.

    • @jeffg4686
      @jeffg4686 4 года назад +2

      @@bostjanvesnicer - Thanks, that's what I was after - that it only compiles for types that are used. That's good to hear.

  • @mustafasalih5328
    @mustafasalih5328 4 года назад +1

    thanks Ryan

  • @ethan-youtubetips8226
    @ethan-youtubetips8226 4 года назад +1

    Great content. You are doing good. Will definitely come back for the next. Thumbs Up 👍

  • @mdshohidurrahman1121
    @mdshohidurrahman1121 3 года назад

    Very effective as always.

  • @TheLegendSpeaker
    @TheLegendSpeaker 3 года назад

    Amazing video! Thanks!

  • @ThePersepolis32
    @ThePersepolis32 2 месяца назад

    awesome! easy to understand.

  • @scott3489
    @scott3489 4 года назад

    Thanks for the awesome content!

  • @lukerhoads
    @lukerhoads 3 года назад

    loved this thanks

  • @TheZdannar
    @TheZdannar 3 года назад

    Amazing video. Thank you.

  • @GlobalYoung7
    @GlobalYoung7 2 года назад

    Thank you 😊

  • @alanhoff89
    @alanhoff89 2 года назад

    Ok, I'm ready to melt down my brain. Lets do this!

  • @aqua3418
    @aqua3418 3 года назад

    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!

  • @meain_
    @meain_ 4 года назад

    Great content. Thanks for sharing.

  • @anishjewalikar
    @anishjewalikar 4 года назад

    Keep up the great work!

  • @TheJacksonblair
    @TheJacksonblair Год назад

    Great video thanks

  • @toddyoung3134
    @toddyoung3134 4 года назад

    But what was the title during the stream!

  • @metaltyphoon
    @metaltyphoon 4 года назад +1

    I think dyn is said as 'dine' as in short for the word dynamic

    • @TheNoirKamui
      @TheNoirKamui 4 года назад +1

      In my head I keep reading it like "din" in dinner. Probably depends on your mother tongue.

  • @muralidharanramanarasimhan8894
    @muralidharanramanarasimhan8894 4 года назад

    i guess there must be a difference between dyn keyword and impl mentioned by Noir?

    • @MichaelKefeder
      @MichaelKefeder 4 года назад

      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 ;)).

  • @philipp332
    @philipp332 2 года назад

    Minute 20: why can you just pass a type to the spellcheck function in the test without instantiating an object first?

  • @arturczajkowski4255
    @arturczajkowski4255 4 года назад

    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.

  • @carcass09
    @carcass09 4 года назад

    What's the VSCode plug-in to automatically display type annotations?

    • @carcass09
      @carcass09 4 года назад

      and parameter names?

    • @RyanLevicksVideos
      @RyanLevicksVideos  4 года назад +1

      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.

    • @carcass09
      @carcass09 4 года назад

      @@RyanLevicksVideos Cheers! Thanks for the great vids:D

    • @carcass09
      @carcass09 4 года назад

      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?

    • @RyanLevicksVideos
      @RyanLevicksVideos  4 года назад

      @@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).

  • @zyxyuv1650
    @zyxyuv1650 2 года назад +1

    Is this channel dead? No updates in a year and a half? Where's the new videos?

  • @jaburullah
    @jaburullah 3 года назад

    Great explanation…

  • @DavidWallace1945
    @DavidWallace1945 Год назад

    man pls make more videos...

  • @bostjanvesnicer
    @bostjanvesnicer 4 года назад +1

    10:25 Good one. Maybe you should ask spellchecker how to spell it?

    • @MatthewHolevinski
      @MatthewHolevinski 4 года назад

      That thumbnail tho :D

    • @joachimm81
      @joachimm81 4 года назад

      @@MatthewHolevinski I thought it said Ryanamic at first glance.

    • @MatthewHolevinski
      @MatthewHolevinski 4 года назад

      @@joachimm81 my brain broke and I legit had no idea what it said

  • @glebnerzhin9376
    @glebnerzhin9376 3 года назад

    thankyougreatvideowillalwaysuseantispacecheckerfromnowon

  • @markocvejic6416
    @markocvejic6416 5 месяцев назад

    why stop making videos?

  • @megumin4625
    @megumin4625 3 года назад

    You have a typo in your code ;P :P ;P

    • @yavuztor79
      @yavuztor79 3 года назад +1

      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.

  • @RemcoJvGrevenbroek
    @RemcoJvGrevenbroek 3 года назад

    Cent you just say
    Let spellcheckers = vec![spellchecker] .....

  • @antwanwimberly1729
    @antwanwimberly1729 Год назад

    Mhmmm
    Rust red hair 👩🏾‍🦰 huh

  • @HunterLeachman
    @HunterLeachman 3 года назад

    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"!