Generic Types in Rust

Поділитися
Вставка
  • Опубліковано 15 січ 2025

КОМЕНТАРІ • 89

  • @letsgetrusty
    @letsgetrusty  3 роки тому +9

    📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet

  • @koustubh7476
    @koustubh7476 2 роки тому +30

    Your explanation is really easy to understand, thank you!

  • @k3rnel_err0r
    @k3rnel_err0r 3 роки тому +34

    I recently discovered your channel I like it so far. I'm big fan of Rust, I cannot say I'm still good at it though. Keep up the good work.

    • @zes7215
      @zes7215 2 роки тому

      no such thing as want or duplication or concise or short or etc, outx, can outx infix any nmw and any s perfect

  • @TheEmbeddedLinuxDude
    @TheEmbeddedLinuxDude 3 роки тому +13

    This was very well explained. Thank you Bogdan!

  • @jaredrethman
    @jaredrethman 3 роки тому +27

    Love your content. The whole way through this video I was certain there would be a performance hit i.e. type coercion (sorry PHP and JS dev here) Then you mentioned it is taken care of! Loving this - thank you so much!

    • @31redorange08
      @31redorange08 3 роки тому +9

      The obvious drawback is that for each concrete type the compiler generates "duplicate" code, leading to a bigger executable.

    • @SemiMono
      @SemiMono 2 роки тому +2

      Yep. Compiling multiple versions is standard for generics in compiled languages. In C++ though, it's a pain in the *** to use generics declared in a separate binary that's linked dynamically.
      I suppose, dynamic linking is a pain in the *** regardless. I'm brand new to rust so I don't know how it handles it yet (does it?)

    • @lacascadaobregon
      @lacascadaobregon 2 роки тому +1

      @@SemiMono It's a pain in the pointer, and a pain in the dereference.

  • @Kollegah9997
    @Kollegah9997 2 роки тому +16

    as a C# Developer this looks just like im using it in C#, Rust is really awesome

  • @tombo615
    @tombo615 2 роки тому +3

    This was a super helpful overview - great job!

  • @bjugdbjk
    @bjugdbjk 3 роки тому +3

    Fabulous Man !!! I was going through the rust book for quite some time, but the topics I was able to cover using ur playlist is far more in great pace !!! tysm , just love ur teaching style !!
    Can see lot of traction of using rust in blockchain, could you make something building common concepts in blokchain using RUST, I guess this will bring lot of traction to ur channel too :)

  • @comicalleel4710
    @comicalleel4710 18 днів тому

    Great explaination finally understood how generics work

  • @adrian_sp6def
    @adrian_sp6def Рік тому +2

    question: 11:18, why fn mixup can not have &self argument? it fails due to T does not implemnt Copy Trait, but why this missing Copy Trait works with self as not a reference? I though that T has no Copy Trait no matter self is a reference or not.

  • @teachforyou6489
    @teachforyou6489 3 роки тому +2

    Thank YOu Bogdan You are really doing superb.

  • @NFLStudy
    @NFLStudy 2 роки тому +1

    Excellent video on a topic that can be difficult for some.

  • @Taetae_1717
    @Taetae_1717 2 роки тому +2

    How do you cast generic type to primitive? Example minutes 09:41, line 8, &self.x + 1

  • @GolangDojo
    @GolangDojo 3 роки тому +4

    What are you doing with your audio? Sounds so clean

    • @letsgetrusty
      @letsgetrusty  3 роки тому +3

      Nothing special, just using the Blue Yeti mic!

    • @ozanmuyes
      @ozanmuyes 3 роки тому +1

      Two eggs in the morning and a glass of whiskey at night 😉

    • @oyewodayo
      @oyewodayo 2 роки тому

      @@ozanmuyes Does this really works or just sarcasm?

  • @sahilverma4077
    @sahilverma4077 3 роки тому +3

    I really think traits are a really good way to limit your template and make them safer, wish we had those in java too (we have something similar but not close, i.e., we can extend from prebuilt classes so that the T type can be only of a child type of only a particular class)

    • @31redorange08
      @31redorange08 3 роки тому

      Not sure what exactly you are missing in Java.

    • @sahilverma4077
      @sahilverma4077 3 роки тому

      @@31redorange08 I don't know if there is a way to limit a genric class's method to only work with a particular class

    • @31redorange08
      @31redorange08 3 роки тому

      @@sahilverma4077 Don't make it generic then.

    • @sahilverma4077
      @sahilverma4077 3 роки тому

      @@31redorange08 have you ever noticed we can have a stream of any class but not of characters

    • @sahilverma4077
      @sahilverma4077 3 роки тому

      I want that kind of feature

  • @devOnHoliday
    @devOnHoliday 9 місяців тому

    7:17
    For Structs, why do we have to define Types T and U if both are used to take any type, and why not just let it be i32 and f32

  • @redcrafterlppa303
    @redcrafterlppa303 2 роки тому +1

    You mentioned that the all needed versions of a generic are created at compile time. So are generics implemented using type erasure like in java or how does it work under the hood?

  • @maksymrachytskyy1677
    @maksymrachytskyy1677 3 роки тому +2

    Looks pretty much like swift ) thank you for your tuts

    • @oyewodayo
      @oyewodayo 2 роки тому

      Same person created both Swift and Rust.

    • @kmaximoff
      @kmaximoff 8 місяців тому

      YES! I love Swift that is why I fall in love with Rust.

  • @tech3425
    @tech3425 4 місяці тому

    10:51 That is so cool

  • @JohnWick-mk4ve
    @JohnWick-mk4ve 3 роки тому +2

    Hi.. great video.. thanks !

    • @exoticcoder5365
      @exoticcoder5365 3 роки тому +1

      I just learnt that John Wick is a programmer

  • @sc5shout
    @sc5shout 3 роки тому +3

    Is there a variadic generic type?

    • @HermanWillems
      @HermanWillems 3 роки тому +1

      :( i think not yet i hope it will be soon.

    • @raffimolero64
      @raffimolero64 3 роки тому

      would be really cool, but not yet :(
      right now the way rust handles variadic arguments for functions is not to write a function but a macro instead.
      macros are able to match a variable number of arguments and often expand recursively.
      you *could* write a macro that creates something based on a variable number of types, but you'd lose the things that make normal generics good: when you use a normal generic, a new type is automatically inferred and created.

  • @WaiTingKuo0527
    @WaiTingKuo0527 2 роки тому +1

    why doesnt my refactoring menu show the "extract function" method? any extension i need to install except rust-analyzer?

  • @rotteegher39
    @rotteegher39 Рік тому

    Do you have an Option and Result enums as a tattoos on your arms?

  • @hanyanglee9018
    @hanyanglee9018 9 місяців тому

    c++ added similar feature in c++20. Basically, this feature is introduced to programming after 2015. People waited for it for at least 20 years.

  • @IvanMorozov-f6w
    @IvanMorozov-f6w 10 місяців тому

    очень полезные видео, спасибо

  • @filipbarbaric1960
    @filipbarbaric1960 2 роки тому

    men you are better than undemy tutorials.

  • @dzibanart8521
    @dzibanart8521 3 роки тому +3

    yoooo nicely explained! subscribed

  • @tech3425
    @tech3425 4 місяці тому

    Loved it

  • @natanfurman2467
    @natanfurman2467 2 роки тому

    Why doesn’t the last example throw an error at line 21, arent x and y private?

  • @lsatenstein
    @lsatenstein 2 роки тому +2

    I have started learning RUST and your videos help me immensely. I follow your explanations and those as well from the PDF files on my desktop.
    Here is one question for you about structures. In C, I can define a structure as a typedef. Is the typedef facility or prototyping function definitions also available in Rust?

    • @Gramini
      @Gramini 2 роки тому

      If I understand typedef correctly, it'S a type alias. Those exist in Rust as well by using the type keyword:
      type TypeAlias = MyStruct;

  • @paperstars9078
    @paperstars9078 Рік тому

    what is the music in the background?

  • @coldsir5406
    @coldsir5406 3 роки тому

    Why do we need to define the type of impl can't we just write witrhout generics like ```impl Point```

    • @raffimolero64
      @raffimolero64 3 роки тому +7

      impl Point means "for every point whose x is any type and y is any type"
      impl Point would mean "for every point whose x and y are the same type"
      impl Point would mean "for every point whose x is f32 and y is any type"

    • @coldsir5406
      @coldsir5406 3 роки тому

      @@raffimolero64 thank you sir

    • @kevinmbtbass
      @kevinmbtbass 2 роки тому +1

      @@coldsir5406 The response doesn't really answer the question. The generic types after the struct name (Point) refer to the fields of the struct, while the generict types after impl (impl) define those types for the methods, etc. inside the impl.
      For example you may have a Point but you want to be able to add to it with either an int or a float:
      impl Point {
      fn add(&self, x: T, y: U) {...}
      }

    • @coldsir5406
      @coldsir5406 2 роки тому

      @@kevinmbtbass got it in the end, thanks

  • @cleverengineer2410
    @cleverengineer2410 8 місяців тому

    this channel as become a school for me

  • @feliperios7536
    @feliperios7536 2 роки тому

    Nice job

  • @nirajgautam403
    @nirajgautam403 10 місяців тому

    Can anyone share some reference for inheritance like functionality in rust

  • @DMZT_dhruv
    @DMZT_dhruv 5 місяців тому

    background music name???

  • @walli33
    @walli33 2 роки тому

    Nice Morgan !!!

  • @orhalimi
    @orhalimi 3 роки тому

    Great video

  • @jabuci
    @jabuci 2 роки тому

    At mixup(), I want the first parameter to be &self, not just self. p1.mixup(p2) consumes both p1 and p2 because of move :(

  • @SemiMono
    @SemiMono 2 роки тому

    New music! :D

  • @christosbinos8467
    @christosbinos8467 2 роки тому

    is self in rust similar to this in javascript?

    • @Gramini
      @Gramini 2 роки тому

      Yes. self / this both refer to the object/struct that the method is defined for.

  • @muneebakhlaq3085
    @muneebakhlaq3085 3 роки тому

    Nice video

  • @raman_scifi2sci
    @raman_scifi2sci 2 роки тому

    awesome

  • @poonikarthu4988
    @poonikarthu4988 2 роки тому

    Instead of taking in a vector of integers, we want to take in a vector of TEA.

  • @caseyyeow1649
    @caseyyeow1649 3 роки тому +3

    Excellent video. Is there a faint background music behind? Quite irritating when you want to concentrate. Thanks. 🙏

    • @letsgetrusty
      @letsgetrusty  3 роки тому +2

      Music is improved in future videos!

    • @caseyyeow1649
      @caseyyeow1649 3 роки тому +1

      @@letsgetrusty No worry. Thx for your excellent video which I would definitely watch first before dive into the detail doc.

    • @caseyyeow1649
      @caseyyeow1649 3 роки тому

      @@letsgetrusty Oh, perhaps without any music would be better? Thx.

    • @exoticcoder5365
      @exoticcoder5365 3 роки тому +1

      @@letsgetrusty I’m the opposite I find the background music helps me to concentrate more on what you said in the video 😂😂😂

    • @exoticcoder5365
      @exoticcoder5365 3 роки тому

      I’m the opposite I find the background music helps me to concentrate more on what he said in the video 😂😂😂

  • @samuelwittlinger7790
    @samuelwittlinger7790 Рік тому +2

    It doesn't slow down performance but it should be noted that heavy use of generics makes your binaries larger.

  • @ehsanisa3759
    @ehsanisa3759 2 роки тому

    chad bogdan

  • @WaiTingKuo0527
    @WaiTingKuo0527 2 роки тому

    better use Ord instead. Partial order doesn't guarantee global maximum exist (mathemetically)

  • @naitikmakwana4286
    @naitikmakwana4286 Рік тому +15

    backgroud music is very distracting..please try to avoid it

  • @kmaximoff
    @kmaximoff 8 місяців тому

    everything is great, except background music is annoying. Makes it hard to focus.

  • @pynchia4119
    @pynchia4119 2 роки тому

    you need to work on the lighting: you seem to be wearing a mask around your eyes or having been up all night...

  • @1234fewgfwe
    @1234fewgfwe 6 місяців тому

    Dude background music isn’t appropriate for coding tutorial videos please 🤣

  • @arthurtapper1092
    @arthurtapper1092 3 роки тому

    Reads straight from Rust book for entire video. "If you don't understand just pause the video and read through."
    People who read rust book and still don't understand: !?!?! Serioiusly? That's why were here