Rust Generics

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

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

  • @julienduris8326
    @julienduris8326 3 года назад +9

    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.

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

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

  • @awais_korai
    @awais_korai Год назад +2

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

  • @kevingzhang
    @kevingzhang 4 года назад +8

    best video explaining generic type in 30 minutes

  • @tobiasfuchsberger900
    @tobiasfuchsberger900 4 года назад +15

    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!

  • @DSaad
    @DSaad 10 месяцев назад +1

    I wish you could make more advanced Rust videos, like error handling and testing! 🙏🏼🙌🏻

  • @annismonadjem6901
    @annismonadjem6901 4 года назад +23

    Thanks Doug for your fantastic courses! Keep it coming. Very helpful to me.

    • @dougmilford7814
      @dougmilford7814  4 года назад +12

      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.

  • @scottb4029
    @scottb4029 Год назад +1

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

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

    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

  • @klimentdukovski
    @klimentdukovski Год назад +1

    Your videos are by far the best ones on Rust and I've watched a lot of them. Thank you, sir 🙏

  • @TON-vz3pe
    @TON-vz3pe Год назад +1

    Fantastic job. I always confused myself with Where clause, type = , what a trait bound means. Now it's clear. Thanks sir.

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

    Doug, your videos are high quality and clear. Thanks for posting!

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

    Thanks Doug . Very helpful to me.❤️👍

  • @kennethmarete5329
    @kennethmarete5329 Год назад +1

    Awesome content, great teacher, articulate lessons, great tutorial. The best I have seen so far. Thanks Doug Milford

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

    Thanks Doug, you are a great teacher.
    Love your content

  • @busydying
    @busydying 4 года назад +9

    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)` :)

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

    20:14 Using println!("{}", result2); expected "18-first-second", but the result presented was i32-first-second.
    Thanks so much for the videos!!!

  • @daviidon
    @daviidon 4 года назад +6

    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.

    • @dougmilford7814
      @dougmilford7814  4 года назад +5

      Yeah, point taken. Often it's easier to learn from real examples. I'll keep that in mind for future videos.

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

      @@dougmilford7814 This is already extremely useful though, thanks.

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

    Doug you're awesome.

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

    Great video!

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

    Doug there are fantastics videos, I hope you're still planning on making these. I would really like to see one on iterators.

  • @Kserx.p
    @Kserx.p 4 года назад +6

    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!

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

      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.

    • @dougmilford7814
      @dougmilford7814  4 года назад +7

      I published the video on Lifetimes. I hope it helps!

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

      Subscribing your channel today ❤️ Thanks for such awesome clips.
      I am expecting some tutorials on diesel queries with postgresql.
      Hope.

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

    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.

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

      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!

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

    Thank you so much! Your Rust series is just awesome, clear and concise!

  • @MrGreen-kq4ds
    @MrGreen-kq4ds 3 года назад +1

    this is gold, thanks!

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

    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🥳

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

    Very helpful 👍 Really Thanks for this.
    I request you please make some tutorial on rust with diesel orm . Not understanding diesel.

  • @ati43888
    @ati43888 Год назад +1

    Thank you so much

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

    Great Video, thanks!

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

    You're a god.

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

    7:07 made me laugh harder than it should have.

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

    This is awesome!!!

  • @priyanshu4016
    @priyanshu4016 Год назад +1

    Hi Doug , can you please start rust coding projects

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

    What if a struct already have a function with the same name as the trait function?

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

    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.

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

    excellent video.

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

    Could you make a video on
    trait Sometrait {
    type Sometype;
    }

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

    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?

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

    What did you do to have the type appear when you hover your mouse ? This doesn't happen in my VScode.

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

      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

  • @360nickx
    @360nickx 4 года назад +1

    doug_func FTW!!!

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

    10:50

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

    14:37 oh no no no... thats absolutely hideous

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

    Wonderful video!

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

      Thank, man! I appreciate the compliment :)