You Should Really Know These Traits in Rust

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

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

  • @Hellbending
    @Hellbending 6 หลายเดือนก่อน +12

    Thank GOD someone that ACTUALLY explains how these things work is making videos on it - you’re a blessing man Ty Ty ❤❤❤❤

    • @oliverjumpertzme
      @oliverjumpertzme  6 หลายเดือนก่อน +2

      Thank you! Stay ready for the next one. We're going to explore a lot more in-depth things about Rust. 😁🙌🏻

  • @xenofly94
    @xenofly94 6 หลายเดือนก่อน +23

    Actually sad that this isn't a series already. You've explained those traits perfectly and it would be awesome to have similar videos for other common std lib traits

    • @oliverjumpertzme
      @oliverjumpertzme  6 หลายเดือนก่อน +5

      Thank you! Well…I might have gotten a few more content ideas now. 💛 Already working on the next video BUT I will definitely take a look at the std lib and see what else is worth being explained and explored a little more. ☺️

    • @irlshrek
      @irlshrek 4 หลายเดือนก่อน

      @@oliverjumpertzme I agree, you did an amazing job explaining these traits! can I politely provide a bit of feedback? While the sounds every time a new element shows up on screen was fancy it was a bit overwhelming and distracting.

  • @john.dough.
    @john.dough. 6 หลายเดือนก่อน +11

    10:14 -> For code snippets intended for language learners, it may help to not use font ligatures, so that people know what to type.
    In this case, the key ligatures "••" means ".." and "⟹" means "=>"

    • @john.dough.
      @john.dough. 6 หลายเดือนก่อน +1

      Great video though! Super helpful! :]

    • @oliverjumpertzme
      @oliverjumpertzme  6 หลายเดือนก่อน +3

      Thank you. :) Yea, I'll definitely change the font next time. Great feedback!

  • @CuriousSpy
    @CuriousSpy 6 หลายเดือนก่อน +7

    You can write From btw

  • @joeymea
    @joeymea 7 หลายเดือนก่อน +7

    Hey man, thanks for taking the time to make this! Rust is definitely lacking in short, advanced topical videos like this. I already knew of the Into trick, but I had never heard of the others!
    Bonus points for showing usage examples because theory isn't quite enough to get through my thick skull!

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน

      Thank you! Oh, and don't forget, you can always do more than only Into! ☺️💛

  • @LinkiPinkiWasTaken
    @LinkiPinkiWasTaken วันที่ผ่านมา +1

    What about cases where you want to convert something into a new owned object, from a borrowed value? Is `impl From for MyOtherStruct` bad practise or did you just not mention it? If it is, why is it bad?

    • @oliverjumpertzme
      @oliverjumpertzme  วันที่ผ่านมา

      You can well do that. A common impl I see (and also use) is From, for example, and even String implements From. :)
      The only thing From implies (by the docs is): The conversion MIGHT not be cheap, or you MUSTN'T rely on it being cheap. It does not specifically say anything about the base value, although in theory, From is meant to take ownership.
      But in the end, it's perfectly fine to do that. The docs just list a few requirements that are usually associated with the conversion:
      1. The conversion is *infallible*
      2. The conversion is *lossless*
      3. The conversion is *value-preserving*
      4. The conversion is *obvious*

  • @Avogadro37540
    @Avogadro37540 6 หลายเดือนก่อน +9

    17:03
    Perfect! Should be my new wallpaper moving forward ^^

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

      Haha, I can send you the png if you want. 😜

  • @maingateway2308
    @maingateway2308 หลายเดือนก่อน +1

    Looks at title and thumbnail.. ah it's another basic beginner topic. Let's give the guy a minute to talk ...
    Video starts.. video ends.. liked and subscribed ❤
    Thanks

  • @lcssbr
    @lcssbr หลายเดือนก่อน +1

    Just found your channel and I'll definitely look into the other videos. Thanks for the content!

  • @alanbaumann
    @alanbaumann 3 หลายเดือนก่อน +1

    I found this very useful, thank you! Also, I'm a big fan of MonoLisa.

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

      Super happy you find it useful! 💛🙌🏻

  • @OlegLecinsky
    @OlegLecinsky 6 หลายเดือนก่อน +1

    Could you add some explosions to those whoosh sounds and shake animations please? It just feels incomplete w/o explosions.

  • @Seacrest.
    @Seacrest. 7 หลายเดือนก่อน +4

    love that amount of creators about Rust grows here

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน +2

      Rust is just worth it. Such a beautiful language! ☺️

  • @Proprogrammer001
    @Proprogrammer001 6 หลายเดือนก่อน +4

    Absolutely brilliant video. So many concepts are now clear now

  • @yapayzeka
    @yapayzeka หลายเดือนก่อน +1

    16:59 very important graph

  • @norude
    @norude 6 หลายเดือนก่อน +1

    Is there any way to make a conversion from MyStruct to a String?
    You can't `impl Into for MyStruct`, because a String is not From
    You can't `impl From for String`, because of orphan rules
    I am stuck

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

      That's not entirely correct. :)
      If MyStruct is really YOUR struct, means, a local type (which is a type that you created and have under your control, read: its source is in one of your project's files), you can implement From for MyStruct as well as From for String.
      But I assume you mean that MyStruct is from a lib not under your control and now you want to implement From for either side?
      In that case, you can still work with the newtype principle. Create a new struct:
      struct Wrapper(ForeignType);
      and implement From for either side now, as Wrapper is now a local type, which means that orphan rules don't apply. :)
      An example:
      impl From for String {
      fn from(value: Wrapper) -> Self {
      // convert ForeignType to String
      }
      }
      Hope this helps?

    • @norude
      @norude 6 หลายเดือนก่อน +1

      ​@@oliverjumpertzmeI understood now, I didn't have a proper understanding of the orphan rules. They state that if any of the type parameters is a local type, the impl is allowed. I assumed that since From and String are not local, the impl is not allowed

  • @laycookie-f6i
    @laycookie-f6i 6 หลายเดือนก่อน +1

    Just started learning rust and I feel like I just leveled up lol

    • @oliverjumpertzme
      @oliverjumpertzme  6 หลายเดือนก่อน +1

      I guess that's a perfect start then!

  • @MaiklPolk
    @MaiklPolk 6 หลายเดือนก่อน +2

    Great video, thank you!

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

      Thank you for taking your time to watch it! 💛

  • @helleye311
    @helleye311 6 หลายเดือนก่อน +1

    This is pretty good, thanks! I keep forgetting you can have the parameter as impl Into instead of just String. And then I'm annoyed when I constantly need to do .to_string() or .to_owned() or into() on my hardcoded text.
    Is there a difference between
    fn foo(s: impl Into)
    and
    fn foo(s: T) where T: Into
    whether that be something semantic or functional?
    Which is preferred for a simple example like this?
    Also I found you can do
    fn foo(s:T)
    and that gets translated to the where syntax. Good, bad, thoughts?

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

      Hey, thanks a lot!

    • @helleye311
      @helleye311 6 หลายเดือนก่อน +1

      ​@@oliverjumpertzmeThat's great to know, thank you! I'm personally fond of putting the bound in the generic, but that's probably just because I'm primarily a typescript dev, and that's how typescript does it.
      Happy to know it's just "whatever you like" and not "well if you use where it's one behavior, and if you use impl it's another, and putting it in generic is the same as where but it implies something else".
      Hopefully there's a clippy rule to enforce using the same thing everywhere. I could get used to where or impl, but I would hate having all 3 scattered about the codebase if working with a team.

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

      @@helleye311 definitely stick to it then! Feeling comfortable and ”at home” in your code is more important than any conventions. The old mantra: do what works best for you. That's the beauty of Rust. You are usually not penalized for doing it one or the other way. ☺️

  • @OfficialViper
    @OfficialViper 2 หลายเดือนก่อน +1

    Keep up the good work! This video is great! :)

    • @oliverjumpertzme
      @oliverjumpertzme  2 หลายเดือนก่อน

      Thanks a lot! 💛 Doing my best to keep it up ☺️

  • @inversebrah
    @inversebrah 6 หลายเดือนก่อน +1

    cool

  • @meanmole3212
    @meanmole3212 2 วันที่ผ่านมา

    Interesting, maybe I will use AsRef now at some point, or I just forget about it like with associated trait types and never use it.

    • @oliverjumpertzme
      @oliverjumpertzme  2 วันที่ผ่านมา

      Rust has a lot of features that even I sometimes tend to forget about (and I use Rust daily 😂). It's like muscle memory. If you've just other languages for long enough, you first need to get used to new systems. Rust, eg. Has a pretty solid one, but that, admittedly, comes with many things to keep in the back of our heads. ☺️

  • @leifelliott1500
    @leifelliott1500 6 หลายเดือนก่อน +1

    nice vid 👍

  • @polanas1879
    @polanas1879 6 หลายเดือนก่อน +1

    That's just top tier Rust content

  • @bayoneta10
    @bayoneta10 3 หลายเดือนก่อน +1

    Good video! Congrats!

  • @sypher4912
    @sypher4912 6 หลายเดือนก่อน +1

    Very nice explanation!!!

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

      Thank you. Glad you liked it! 💛

  • @kaziibrahimkhalil1011
    @kaziibrahimkhalil1011 6 หลายเดือนก่อน +1

    Beautifully explained. Everytime u publish a video my heart goes... Yayy a complete tutorial on rust🎉...but not😢...I can not explain how good i feel working with u...keep up ur good work and heart❤😋❤. Thanks for ur contribution.

  • @catsolstice
    @catsolstice 2 หลายเดือนก่อน +1

    Good content 👍

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

    Nice video - thanks, I learned something, and your explanation style is very good.
    For what it's worth, I think the frequent sound effects are cute at first, but become highly distracting and in at least one case genuinely alarming. Maybe they should be a lot quieter, and/or have some subtle variation to make them less jarring?

    • @oliverjumpertzme
      @oliverjumpertzme  6 หลายเดือนก่อน +1

      Thank you for this feedback. I'll experiment with the sound a little more in my next video and see whether I can blend it more in. 🙏🏻

  • @avalagum7957
    @avalagum7957 6 หลายเดือนก่อน +1

    Thank you very much. I just subscribed to your channel. Hope to have more videos like this from you. Thanks again.

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

      Hey, thanks a lot! You can count on me creating many more videos ☺️ Already working on the next!

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

    Omg thank you so much, man, I'm loving your content. It really helps 🙏🏻🌱

    • @oliverjumpertzme
      @oliverjumpertzme  3 หลายเดือนก่อน +1

      Thank you! Super happy you like it! 💛

  • @abdo_omareg
    @abdo_omareg 6 หลายเดือนก่อน +1

    Another great video, very educational with lots of examples and straight to the point.

    • @oliverjumpertzme
      @oliverjumpertzme  6 หลายเดือนก่อน +1

      Thank you! 💛🙏🏻 Glad you like it!

  • @equu497
    @equu497 6 หลายเดือนก่อน +1

    You know man, I've been trying and trying and trying to learn traits and why I need them for a loooong time now. Always found ways around it but I'm glad I came across your video, it helped more than I can express. Id love to see more from you

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

      Super happy to read that, man! 💛 My next video might have a few more reasons for you then. Still working on it, but I think it will teach you a few more things. ☺️

  • @luiscarlosjayk
    @luiscarlosjayk 4 หลายเดือนก่อน

    Very useful! Thanks

  • @LibreGlider
    @LibreGlider 5 หลายเดือนก่อน

    Just so you know I was the 1000th sub. Congrats from a future Rustacean!

    • @oliverjumpertzme
      @oliverjumpertzme  5 หลายเดือนก่อน

      Wooohooooo! Thanks a lot! 💛🙌🏻

  • @simonkalu
    @simonkalu 6 หลายเดือนก่อน +1

    Awesome

  • @irlshrek
    @irlshrek 4 หลายเดือนก่อน +1

    omg. mind blown! AsRef has always been floating in my head as a fuzzy vague thing and you demystified it for me! thank you!

    • @oliverjumpertzme
      @oliverjumpertzme  4 หลายเดือนก่อน +1

      Super happy to read that! 💛🙌🏻

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

    Really good content, thank you so much for the explanation!

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

      Thank you so much for these kind words! 💛🙏🏻

  • @APerson-jf2md
    @APerson-jf2md 2 หลายเดือนก่อน +1

    3:04 - that got me confused for a moment :D
    You meant the opposite: Into implies From
    T: Into -> T: From
    but not the other way around.

    • @APerson-jf2md
      @APerson-jf2md 2 หลายเดือนก่อน +1

      ok.. - with the TryFrom you said it again, but now I understand what you mean.. You were talking about the blanket impls and not the type in itself..
      So "a type that is Into implies it is From", but "implementing From" automatically "creates an implementation for Into", meaning "it implies the existence of an implementation of Into".
      But maybe my brain is wrong, or too nit-picky ;)
      Anyway, great videos!

    • @APerson-jf2md
      @APerson-jf2md 2 หลายเดือนก่อน

      more nit-picking... sorry :)
      14:30 this is not the "newtype idiom", but standard struct composition
      newtype is a thin wrapper around a type, mostly a zero-cost abstraction, so most of the time a tuple type like:
      struct Bytes(u32);
      struct Kilobytes(u32);
      (with possible conversions implemented) to prevent accidental mismatches in
      fn copy_data(data: ..., length: Kilobytes) {...

    • @APerson-jf2md
      @APerson-jf2md 2 หลายเดือนก่อน +1

      17:17 and my OCD says: "P" should be "T"
      .. ok.ok.. I'll shut up!... ;)

    • @oliverjumpertzme
      @oliverjumpertzme  2 หลายเดือนก่อน +1

      doc.rust-lang.org/rust-by-example/generics/new_types.html ☺️

    • @oliverjumpertzme
      @oliverjumpertzme  2 หลายเดือนก่อน

      😜

  • @emdeization
    @emdeization 6 หลายเดือนก่อน +1

    Good stuff

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

      Thank you! ❤️‍🔥🙏🏻

  • @cthutu
    @cthutu 7 หลายเดือนก่อน +1

    Excellent video and great presentation of some fundamental concepts in Rust.

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน

      Thank you very much! Super happy to read that you liked it. It really means a lot to me! 💛

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

    8:14 HTTP/3 (HTTPS only) works over UDP/IP

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

      That's true, but it only accounts for ~30% of internet traffic. http(s) and http2 still account for ~68% of all traffic. :)

  • @RiwenX
    @RiwenX 7 หลายเดือนก่อน +1

    Thanks, I really needed this video as a refresher of my dormant knowledge

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน

      Super happy to hear that. Thanks a lot for watching! 💛

  • @KylePrinsloo
    @KylePrinsloo 7 หลายเดือนก่อน +1

    I don't know Rust, but you covered it well and looks interesting :) thanks for the vid!

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน +1

      Thank you, Kyle! Oh, and congratulations on your new Podcast! Haven't had the time to watch it yet but it's the next on my list. 💛

    • @KylePrinsloo
      @KylePrinsloo 7 หลายเดือนก่อน +1

      @@oliverjumpertzme thanks man :)

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

    great! 3:00 is my favorite part of the rust std lib

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

      Rust's std is incredible as a whole! 💛 Not much bs, the minimum required, but the best quality possible. ☺️

  • @WhiteSponge
    @WhiteSponge 6 หลายเดือนก่อน +1

    Really good video! subscribed!

  • @jpp855
    @jpp855 2 หลายเดือนก่อน

    Não entendi porra nenhum, mas acho que você explicou bem, me falta fundamentos.

    • @oliverjumpertzme
      @oliverjumpertzme  2 หลายเดือนก่อน +1

      First of all: thank you. Second: super sorry you think you lack the fundamentals. Any way I can try to help you to improve the situation? ☺️

    • @jpp855
      @jpp855 2 หลายเดือนก่อน +1

      @@oliverjumpertzme still learning Rust, I have just a basic idea about From, Try, Into… thank you concern! I will visit your video on future. So, you already helped.

  • @marcopaolovaleriovezzoli5776
    @marcopaolovaleriovezzoli5776 7 หลายเดือนก่อน +1

    Amazing and really important.

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน

      Thank you very much! 💛🙏🏻

  • @anneallison6402
    @anneallison6402 6 หลายเดือนก่อน +1

    Very good explanation!

  • @SomethingSomething1337
    @SomethingSomething1337 6 หลายเดือนก่อน +1

    this is so clear now! thank you!

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

      Hey, super happy you find it useful! 💛

  • @TooFatToKidnap
    @TooFatToKidnap 7 หลายเดือนก่อน +1

    another banger video. keep up the good work Oliver 👍

    • @oliverjumpertzme
      @oliverjumpertzme  7 หลายเดือนก่อน +1

      Thank you very much! Already working on the next. Trying to improve every time. 💛🙏🏻

    • @mateocalvo6138
      @mateocalvo6138 7 หลายเดือนก่อน

      Using strings in factory methods I thought "there must be a better way to do this". I now know the way, thanks