Dynamic vs Static Dispatch in Rust

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 93

  • @parthikpatel6108
    @parthikpatel6108 3 ปีที่แล้ว +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 2 ปีที่แล้ว +2

      @@xrafter probably

  • @MrAnandml
    @MrAnandml 3 ปีที่แล้ว +5

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

  • @guidyouguy7306
    @guidyouguy7306 2 ปีที่แล้ว +4

    hey long time, we need more rustttttttttttttttt

  • @AndrewBanchich
    @AndrewBanchich 3 ปีที่แล้ว +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

  • @jamie_rides
    @jamie_rides 3 ปีที่แล้ว +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!

  • @pandulaweerasooriya7689
    @pandulaweerasooriya7689 2 ปีที่แล้ว

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

  • @joaodiasconde
    @joaodiasconde 3 ปีที่แล้ว +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

  • @jeffg4686
    @jeffg4686 3 ปีที่แล้ว +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.

  • @360nickx
    @360nickx 3 ปีที่แล้ว +2

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

  • @numtostr
    @numtostr 3 ปีที่แล้ว +4

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

  • @jashanj0tsingh
    @jashanj0tsingh 3 ปีที่แล้ว +1

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

  • @joelmontesdeoca6572
    @joelmontesdeoca6572 2 ปีที่แล้ว +1

    Presentation was on 🔥! Thanks! 👋🏼👍🏼

  • @Tigregalis
    @Tigregalis 3 ปีที่แล้ว +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.

  • @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 3 ปีที่แล้ว +1

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

  • @markmcdonnell
    @markmcdonnell 2 ปีที่แล้ว

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

  • @sffortytwo
    @sffortytwo 2 ปีที่แล้ว

    Well explained and just the right amount of depth.

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

  • @darkarie
    @darkarie ปีที่แล้ว

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

  • @LeKrul
    @LeKrul 6 หลายเดือนก่อน

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

  • @ethan-youtubetips8226
    @ethan-youtubetips8226 3 ปีที่แล้ว +1

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

  • @dabrick100
    @dabrick100 3 ปีที่แล้ว +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?

  • @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!

  • @TheNoirKamui
    @TheNoirKamui 3 ปีที่แล้ว +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 3 ปีที่แล้ว +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!

  • @tomasz-waszczyk
    @tomasz-waszczyk ปีที่แล้ว

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

  • @arturczajkowski4255
    @arturczajkowski4255 3 ปีที่แล้ว +1

    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  3 ปีที่แล้ว +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 3 ปีที่แล้ว

      @@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 3 ปีที่แล้ว

      what if it's a Box?

    • @RyanLevicksVideos
      @RyanLevicksVideos  3 ปีที่แล้ว

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

    • @arturczajkowski4255
      @arturczajkowski4255 3 ปีที่แล้ว

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

  • @austecon6818
    @austecon6818 2 ปีที่แล้ว

    These videos are really really helpful. Thank you.

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

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

  • @AlexeyYunoshev
    @AlexeyYunoshev ปีที่แล้ว

    Thank you! Perfect pace

  • @alanhoff89
    @alanhoff89 2 ปีที่แล้ว

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

  • @jeffg4686
    @jeffg4686 3 ปีที่แล้ว +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 3 ปีที่แล้ว +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 3 ปีที่แล้ว +2

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

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

  • @patix0331
    @patix0331 3 ปีที่แล้ว

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

  • @zyxyuv1650
    @zyxyuv1650 2 ปีที่แล้ว +1

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

  • @sagnikbhattacharya1202
    @sagnikbhattacharya1202 3 ปีที่แล้ว +1

    This is amazing!!! Thanks :D

  • @mdshohidurrahman1121
    @mdshohidurrahman1121 3 ปีที่แล้ว

    Very effective as always.

  • @amidfallen
    @amidfallen ปีที่แล้ว

    very educative, thank you!

  • @mustafasalih5328
    @mustafasalih5328 3 ปีที่แล้ว +1

    thanks Ryan

  • @metaltyphoon
    @metaltyphoon 3 ปีที่แล้ว +1

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

    • @TheNoirKamui
      @TheNoirKamui 3 ปีที่แล้ว +1

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

  • @TheLegendSpeaker
    @TheLegendSpeaker 3 ปีที่แล้ว

    Amazing video! Thanks!

  • @ThePersepolis32
    @ThePersepolis32 22 วันที่ผ่านมา

    awesome! easy to understand.

  • @alexzander__6334
    @alexzander__6334 2 ปีที่แล้ว

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

  • @toddyoung3134
    @toddyoung3134 3 ปีที่แล้ว

    But what was the title during the stream!

  • @TheZdannar
    @TheZdannar 3 ปีที่แล้ว

    Amazing video. Thank you.

  • @meain_
    @meain_ 3 ปีที่แล้ว

    Great content. Thanks for sharing.

  • @scott3489
    @scott3489 3 ปีที่แล้ว

    Thanks for the awesome content!

  • @anishjewalikar
    @anishjewalikar 3 ปีที่แล้ว

    Keep up the great work!

  • @lukerhoads
    @lukerhoads 3 ปีที่แล้ว

    loved this thanks

  • @GlobalYoung7
    @GlobalYoung7 2 ปีที่แล้ว

    Thank you 😊

  • @TheJacksonblair
    @TheJacksonblair ปีที่แล้ว

    Great video thanks

  • @muralidharanramanarasimhan8894
    @muralidharanramanarasimhan8894 3 ปีที่แล้ว

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

    • @MichaelKefeder
      @MichaelKefeder 3 ปีที่แล้ว

      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 ปีที่แล้ว

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

  • @DavidWallace1945
    @DavidWallace1945 ปีที่แล้ว

    man pls make more videos...

  • @jaburullah
    @jaburullah 3 ปีที่แล้ว

    Great explanation…

  • @carcass09
    @carcass09 3 ปีที่แล้ว

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

    • @carcass09
      @carcass09 3 ปีที่แล้ว

      and parameter names?

    • @RyanLevicksVideos
      @RyanLevicksVideos  3 ปีที่แล้ว +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 3 ปีที่แล้ว

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

    • @carcass09
      @carcass09 3 ปีที่แล้ว

      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  3 ปีที่แล้ว

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

  • @bostjanvesnicer
    @bostjanvesnicer 3 ปีที่แล้ว +1

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

    • @MatthewHolevinski
      @MatthewHolevinski 3 ปีที่แล้ว

      That thumbnail tho :D

    • @joachimm81
      @joachimm81 3 ปีที่แล้ว

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

    • @MatthewHolevinski
      @MatthewHolevinski 3 ปีที่แล้ว

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

  • @glebnerzhin9376
    @glebnerzhin9376 3 ปีที่แล้ว

    thankyougreatvideowillalwaysuseantispacecheckerfromnowon

  • @arturczajkowski4255
    @arturczajkowski4255 3 ปีที่แล้ว

    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.

  • @markocvejic6416
    @markocvejic6416 3 หลายเดือนก่อน

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