Advanced Traits in Rust

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

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

  • @letsgetrusty
    @letsgetrusty  2 года назад +5

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

  • @evidgamer1699
    @evidgamer1699 2 года назад +7

    This is probably the most comprehensive tutorial for Rust. Like the way how precisely you explain things.

  • @ilyasb4792
    @ilyasb4792 2 года назад +31

    I don't know if they are considered advanced, but you could've talked about auto traits, the !traits and the Sync and Send.

    • @scheimong
      @scheimong 2 года назад +14

      auto, negative (!), and optional (?) trait would be good advanced topics to cover IMO. Sync and Send probably fits better in multithreading videos.

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

      @@scheimong that's true.

    • @letsgetrusty
      @letsgetrusty  2 года назад +10

      Will have to make another video about that :)

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

      @@scheimong
      The only optional "?" Trait in rust is "Sized" .

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

      Did another video about marker traits get made. I still don't understand how they work. Effectively they're empty traits so I just don't understand how they're useful when used (for example) as trait bounds?

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

    Just got the cheat sheet. Very nice! I might suggest adding .or_insert_with to the HashMap functions, because you can use it to insert a value returned from a closure without running the closure if the map already has the key. (Apparently parameter expressions are evaluated before functions are called, unless the parameter type is constrained to FnOnce by the function signature.)

  • @karanvknarayanan
    @karanvknarayanan 2 года назад +5

    🦀🦀🦀🦀🦀 Rust forever 🔥🔥🔥🔥🔥🔥🔥

  • @Galakyllz
    @Galakyllz Год назад +5

    At 4:02 you suggested that the main reason to choose associated types over generics (in specific situations) was because you may want a concrete type, but don't generics specify the concrete type as well, the one passed into the impl Iterator< *T* >? I'm still not understanding why I would ever choose to limit how others may use my traits to only one implementation per struct.

    • @polnio
      @polnio 23 дня назад

      At 5:44 you have a great example from standard library: you have a generic for the right member, because a type can be added by many other types. However adding two given types always return the same type, so the output is an associated type

  • @gileet
    @gileet 2 года назад +2

    I really like your videos. Already rust is my second lang, thanks :)

  • @rainerwahnsinn3262
    @rainerwahnsinn3262 Год назад +4

    6:00 Correction: the RHS is the type for the second operant of the sum, not the return type.

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

    I finally understood the difference with Generics and Associated Types, thanks!

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

    I keep coming back to to these videos, mainly because i don't understand shit in the first time, then as I learn more by practice, I come back and see that I understand a little bit more and more. Wish these were also beginner friendly. I still get confused and zone out a lot on this 😂

    • @Joshua-c
      @Joshua-c Год назад

      Same here, but I see progress so I keep going

  • @jonxslays
    @jonxslays 2 года назад +2

    imagine not being subscribed. let’s get rusty breh.

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

    Hey man, I'm really enjoying your videos, they are a great learning resource!

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

    Nice series !

  • @havocthehobbit
    @havocthehobbit 7 месяцев назад

    I was about to say , then you could use traits for operator overloading , then 10 secs later , you go into operator overloading ... lol cool

  • @Speykious
    @Speykious 2 года назад +2

    I definitely didn't know about the last one. I wonder if some libraries actually use that kind of pattern, so far I haven't seen it.

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

      I don't know about any libraries, but there is another thing. In std Rust containers you can't specify the way it sorts or compare its elements (e.g. BTreeSet or HashMap) by providing some functor to do it (this is C++ way). Std containers only uses impls of contained type (BTreeSet requires Ord trait).
      So, for example, there is a struct Student, that has average score and age. How you can say if one student is "less" than other? Well, in general case you can't make an Ord trait impl. But in specific case you can use neotype pattern to wrap your student and impl Ord trait for it, using e.g. age as a main parameter.
      So even std library is pushing us to use this pattern)

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

      @@arjentix interesting

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

    Can you please make a tutorial about tui-rs that would be really cool after the book of course

  • @alerya100
    @alerya100 Месяц назад

    beautiful English, Bogdan. Приємно чути!

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

    I love the highlights your VSCode extension is adding to the "derive" macro, what's the extension you're using called?

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

      Rust analyzer

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

    i really like the code examples... *waving arms furiosly*!

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

    I like the series, thanks. Maybe slightly a little fast, constructive feedback 😉

  • @dzarko55
    @dzarko55 7 месяцев назад

    Sometimes, generic make you write dumb things like
    ::into(mystruct)
    If the compiler can’t decide what you’re trying to turn MyStruct into

  • @user-bt8tg7ct4i
    @user-bt8tg7ct4i 11 месяцев назад

    in ur first example what would counter.next() return?

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

    Good explaination. Thanks!

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

    Nice channel mate, subbed

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

    Very good.... Continue.

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

    Rusty videos as always! :)

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

    great channel!

  • @igorsk1133
    @igorsk1133 11 месяцев назад

    i see that rust very fast compiling on your pc, could you share your hardware specs?

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

    Hi
    Can you share what are all the extensions that you are using for VScode
    I see you have Run|Debug on your main and also Implementations on your tratis.
    Also I see VSCode is helping you code autocompletion when you are implementing rust.
    I will be a great help if you can share those extensions
    Thank you!

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

      I use rust-analyzer. A video going over my entire setup is on the way!

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

    At 10:07, why doesn't Rust make it possible to do something like Human::::fly()? Or even with the instance as human::::fly()?

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

    Based Bogdan :) Thx for this video

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

    Please make a series on Actix also

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

    how about some testing and moqing

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

    штракт, штринг

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

      exactly, my ears are literally bleeding when I hear shtruct, shtring.

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

      in german schtruct, schtring :)

  • @ari-mcbrown
    @ari-mcbrown 2 года назад

    Let's be honest, that human is never gonna fly without a proper Naruto-run in advance.

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

    need some help with surrealdb

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

    I love you. Sorry that's only for Mrs Moore!

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

    Can you talk about std::any?

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

    So you started the video by telling us to subscribe, before we (newcomers) have even seen evidence of why we should. This is even more annoying than the customary "like, comment, and subscribe" found at the end (which you ALSO had). On the other hand, it was impressive how I'd ask a question at my screen and you several times answered it almost immediately. So, maybe I'll upvote the NEXT video of yours that I watch. Assuming it doesn't do the subscription-solicitation-at-the-beginning thing again, at least.

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

    Sounding kinda soft my dude