A Simpler Way to See Results

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ค. 2024
  • Result is Rust's error handling type that is often discussed in the same (or similar) breath as Option, but it feels... scarier. But in this video, I'll argue that that relationship with Option is a useful piece to focus on; they are isomorphic in certain circumstances, and even when they're not, you can think of them as coexisting on a continuum. Then we'll talk about the dreaded/beloved question mark, FromIterator/collect, and some Error stuff.
    Special guest appearances from anyhow, thiserror, derive_more, and boxed Error trait objects; Haskell do-notation, applicative functors, and the first official time I've ever said 'monad' on this channel; and more.
    Links I promised:
    Study of std::io::Error - matklad.github.io/2020/10/15/...
    thiserror - docs.rs/thiserror/latest/this...
    Other stuff:
    Result module docs - doc.rust-lang.org/std/result/
    Result chapter in the book - doc.rust-lang.org/book/ch09-0...
    ! - doc.rust-lang.org/std/primiti...
    Haskell do notation - en.wikibooks.org/wiki/Haskell...
    Sum type - en.wikipedia.org/wiki/Tagged_...
    Isomorphism - en.wikipedia.org/wiki/Isomorp...
    Bottom type - en.wikipedia.org/wiki/Bottom_...
    I use the amazing Manim library for animating these videos, and I edit them with Blender and Audacity.
    www.manim.community/
    www.blender.org/
    www.audacityteam.org/

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

  • @jackkendall6420
    @jackkendall6420 9 หลายเดือนก่อน +409

    I wish your channel had twenty hours of videos like this to binge.

    • @_noisecode
      @_noisecode  9 หลายเดือนก่อน +197

      on it

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

      @@_noisecodeim excited but don’t rush them, they’re so good at this level of quality :)

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

      same, these might be the most interesting Rust videos on YT (sorry Jon, sorry No Boilerplate)

  • @antonpieper
    @antonpieper 9 หลายเดือนก่อน +208

    Your videos are all so high quality! Your Videos are Result

    • @_noisecode
      @_noisecode  9 หลายเดือนก่อน +51

      legendary comment

    • @zyansheep
      @zyansheep 9 หลายเดือนก่อน +11

      @@_noisecode
      let your_videos = Result

    • @RenderingUser
      @RenderingUser 8 หลายเดือนก่อน +2

      When he uploads, there is only one Option, until there is none

  • @lemongrasscap8693
    @lemongrasscap8693 9 หลายเดือนก่อน +8

    I'm way too deep into this cult I mean programming language

  • @mattshnoop
    @mattshnoop 9 หลายเดือนก่อน +11

    5:32 I was going to bring up this exact point and then you said it. There have been tons of times where I've returned `Result` specifically because, to me, there is a semantic difference between "I have nothing to return to you" and "this operation *failed*."

  • @AbelShields
    @AbelShields 9 หลายเดือนก่อน +99

    Thiserror is a good choice for libraries, anyhow makes sense for applications. You shouldn't use anyhow in libraries (since it forces any applications using it to use anyhow too), but thiserror produces normal enums, it just saves boilerplate. You can use it for applications too, although some people prefer the ease and context capabilites of anyhow.

    • @Luxalpa
      @Luxalpa 8 หลายเดือนก่อน +12

      The advantage of anyhow is that you don't need to handle specific error cases, you can just say "oh whatever, when there's an error I'm just gonna print the error message to the screen" or something like that. On the other hand, if you actually do care about which specific error you get (say for example you want to recover from the error in different ways depending on what happened), then using enums / thiserr is the way to go! And for library code, probably very rarely want to use anyhow (and never want to have an anyhow::Result exposed from your API!).

  • @NoBoilerplate
    @NoBoilerplate 9 หลายเดือนก่อน +2

    Glorious! The Haskell aside is the cherry on top for me 👌👌

  • @CorneliusCornbread
    @CorneliusCornbread 9 หลายเดือนก่อน +145

    One thing that drives me absolutely bonkers nuts is when libraries have custom error types that don't implement the Error trait. PLEASE if you are making a library implement the Error trait on your error types, without it being able to generically handle errors is literally impossible.

    • @rileydavidjesus
      @rileydavidjesus 8 หลายเดือนก่อน

      I usually just use std when I need something to handle the generic error.

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

      Use thiserror

    • @angeldude101
      @angeldude101 3 หลายเดือนก่อน +4

      Small problem with implementing std::error::Error: Sometimes std does not exist. For libraries intended to be usable in low level environments where many of the functions of std don't even make sense, it's common to target core instead. Now, the Error trait is not one of those things that doesn't make sense in a low level context... which is why so many have wondered why it wasn't in core to begin with, and now it's _beginning_ to appear in core, but also nightly only.

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

      @@angeldude101 In the meantime, what is the general rule for low level envs? I'm starting to do some embedded systems stuff with rust on a pi pico. Just panic?

  • @orciument
    @orciument 9 หลายเดือนก่อน +62

    I actually didn't know what Infallible was for, this was definitely a good video!

    • @KohuGaly
      @KohuGaly 9 หลายเดือนก่อน +4

      Infallible is actually a workaround for the limitations of Rust syntax and type system when it comes to the ! never type. It is likely one of them will be made just alias for the other somewhere down the line.

    • @spaghettiking653
      @spaghettiking653 8 หลายเดือนก่อน

      @@KohuGaly Glad to see I'm not the only one who sees an issue with this. I find it bizarre to use a special type just to circumvent a problem that's fundamentally caused by forcing a function to return an error when it's not possible for that to happen.

  • @Xld3beats
    @Xld3beats 8 หลายเดือนก่อน +4

    That last line blew my mind! A result without an err is isomorphic to a bool. Pretty new to rust, but result and option seem a LOT better than doing "if data != null" checks in JS

  • @nathanoy_
    @nathanoy_ 9 หลายเดือนก่อน +46

    Your channel has a bright future ahead and I will watch your success with great pleasure.

  • @saxpy
    @saxpy 9 หลายเดือนก่อน +22

    You have a flavor of type theory / category theory when describing the isomorphisms of Result ~ Option and Result ~ T. I'm curious to watch your other videos if you would cover things such as dependent types, const N: usize, and what GATs map to in the realm of type theory. Thanks for the video!

  • @bcsb1001
    @bcsb1001 5 หลายเดือนก่อน +11

    9:40: As a fellow Haskell and Rust enthusiast, I must point out for extra completeness that liftA2 (from Control.Applicative) and on (from Data.Function) can shorten this even further:
    wnew = liftA2 W `on` fallible
    Great video, and the Haskell reference was the cherry on top.

  • @ETBCOR
    @ETBCOR 9 หลายเดือนก่อน +59

    I love your Rust videos so much! You're so so good at helping my mental model of things improve. Keep up the banger work!

  • @danielgysi5729
    @danielgysi5729 8 หลายเดือนก่อน +8

    These videos are incredible. It's so hard to find programming videos for any language that don't assume the viewer is a total noob to programming in general. I love this because, even though I'm already familiar with Option, Result, From, and all the other std library stuff, I didn't know about thiserror and anyhow. I just hope the rust community is a big enough audience to sustain this channel.

  • @jacksonbourne
    @jacksonbourne 8 หลายเดือนก่อน +3

    Note that the compiler will correctly infer Vec for T in the Result if you just provide Result. You could simplify Ok(Self(v?)) even further with a `.map(Self)` instead :)

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

    You should write a book about Rust. The way you are explaining it is simply amazing ❤

  • @HyperFocusMarshmallow
    @HyperFocusMarshmallow 9 หลายเดือนก่อน +2

    The real gem in this video is as the derive_more crate.
    The rest was great as well, but I felt at home with most of this. It’s nice to just hear it in detail and twist and turn concepts around an look at them from different direction. It really helps solidify the ideas.

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

    Coming to Rust from Haskell just wanted to say I appreciated the brief digression into what this would look like with do-notion in the Either monad. I really respect Rust's unified approach to using Result everywhere rather than exceptions. Got a lot out of your video, thanks.

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

    Your Rust videos remind me very much of Meyers' two Effective C++ books (which I devoured when they came out). I really look forward to more in this vein. Thank you.

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

    I just discovered your rust videos and I absolutely love them. Subbed and liked

  • @bobbybyrne1899
    @bobbybyrne1899 9 หลายเดือนก่อน +11

    Thanks Logan, great video. I'm currently working in another language and miss using Rust, and videos like these keep me fresh and up-to-date on the language.

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

    Great video about error handling with Result and Option. I even learned a few things new to me. Top notch content. Subscribed!

  • @DucBanal
    @DucBanal 9 หลายเดือนก่อน +3

    I will chime in with the other comments.
    You have found a great niche in the Rust educational landscape. Please continue exploring more and more tricky Rust concepts.
    Thank you for your work !

  • @misha312
    @misha312 9 หลายเดือนก่อน +2

    I have to confess I am always learning so much about Rust with all your videos!! The more I watch, the more I realise how wonderful and powerful Rust is as a programming language. Thank you so much!

  • @rsnively
    @rsnively 9 หลายเดือนก่อน +10

    Wow this is exactly the kind of video I was hoping for. Thinking about Result as a generalization of Option is a really helpful mindset for thinking about the two types. Even if it's a little more nuanced than that, I think I get too hung up on the extra context that the "Ok" and "Err" names seem to provide. It always bothered me that it's accepted convention for Either to be used this way in Haskell, and I always thought it was just a chance for a "Right is right, lol" joke. But this video really clearly illustrated how helpful of a framework that is.

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

    Your content is absolutely top-notch. Please keep making more.

  • @asp-uwu
    @asp-uwu 9 หลายเดือนก่อน +3

    Awesome video as always! It should be noted that Result also has a rich meaning - if this function returns, there has been an error. For example, a program that loops forever until some error occurs, like a server. Although, in this context, the name "Infallible" leaves a lot to be desired x)

    • @PeterAuto1
      @PeterAuto1 9 หลายเดือนก่อน +3

      you can do Result

    • @asp-uwu
      @asp-uwu 9 หลายเดือนก่อน +1

      @@PeterAuto1 Never type is my beloved, but unfortunately it's not in stable :,(

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

    I am loving this in depth discussion of rust types and their usage. Keep up the good work!

  • @kevinwezenter9183
    @kevinwezenter9183 9 หลายเดือนก่อน +3

    Your content is VERY helpful in reasoning about rust!
    I shared your channel on 2 disc servers to potentially help others...and to give back to you for your hard work!
    Keep it up, man

  • @user-hn8np1mj6t
    @user-hn8np1mj6t 9 หลายเดือนก่อน +3

    Your Rust videos is a gem. Errors is a hot topic and extremely undervalued here on youtube. It should be covered more deeply. Errors in Rust is something that very much differs from other languages

  • @dyslexicsoap7605
    @dyslexicsoap7605 9 หลายเดือนก่อน

    I subscribed only a short while ago and I see your subscriber count is climbing FAST. These are really good videos.

  • @cole.maxwell
    @cole.maxwell 8 หลายเดือนก่อน +1

    What a FANTASTIC video! Thank you for putting this together. Loved the animation and color coding as you explain!

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

    Great video! I'm new to Rust and this helped me out a lot with a toy project I'm working on where I was having issues chaining iterators and dealing with flip flopping between Options and Results. Looking forward to future Rust videos!

  • @TheRedAstro
    @TheRedAstro 9 หลายเดือนก่อน +3

    You have one of the best Rust channels on youtube. Thanks so much for the clarity and quality of all your videos.

  • @parkermcmullin9108
    @parkermcmullin9108 9 หลายเดือนก่อน

    Wow, I really appreciated how you stepped through these. Thank you!

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

    I love watching your videos about Rust! So clean and elegantly explained, with personal remarks so that you're not like a robot. Amazing!

  • @Turalcar
    @Turalcar 9 หลายเดือนก่อน +2

    One of the annoying things about using Infallible is that Ok(v) is not considered exhaustive for Result so I have to do r.unwrap_or_else(|e| match e {}) or something like that.

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

    One more channel, telling so much useful information about Rust! I'm all for it, thank you for your videos!

  • @natashavartanian
    @natashavartanian 9 หลายเดือนก่อน +3

    I WILL take what you present today as some added nuance for my existing understanding

  • @kirglow4639
    @kirglow4639 9 หลายเดือนก่อน

    I hope your channel takes off even more! Awesome informative videos

  • @benjaminkinga7797
    @benjaminkinga7797 8 หลายเดือนก่อน

    These videos are so good!! Love the use of the Manim library

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

    Have I ever used Rust?: No.
    Will I ever use Rust?: Probably not.
    Do I know most of the things he is talking about?: Definitely not.
    Did I enjoy the video?: Yes

  • @J-Kimble
    @J-Kimble 9 หลายเดือนก่อน +1

    Maaan.. I've said this on a previous video of yours, but still the best rust content on YT!
    I think what makes your videos great is that you actually explain the theory and logic behind the type system, so that what-s and why-s are a lot simpler to understand.

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

    Thank you so much for putting this video together. It's very rare to see videos where programmers dive into the mental models of how to use features and patterns so that alone is incredibly helpful.
    That aside, the relationship you've established between Result and Option makes a lot of sense, I was wondering if the difference between the two was just that in one of the them you can access an `Err` but this explanation made me understand the uses much better.
    Hope you continue to make cool videos like these! 🙏

  • @bissbort
    @bissbort 9 หลายเดือนก่อน

    Your explanations are great. Please keep up the good work!

  • @JoeNathan-tl8up
    @JoeNathan-tl8up 9 หลายเดือนก่อน +1

    Awesome video, I'm learning rust, I struggle a lot when working with results (how to unwrap, chain them...etc), videos like yours are very helpful. Thanks 🙏

  • @zacharymontgomery9328
    @zacharymontgomery9328 9 หลายเดือนก่อน +2

    I really love these videos. The precision with which you approach analyzing how and why a piece of code does what it does, and in describing it, is something I have actually been looking for. Along with explaining computation theory with things like data structure isomorphisms, explaining side points like the Never type and the reasons for its existence... it feels like what you are going for is a combination of 'know your tools', with knowing the topic and the practical application. Impressed by how you combine these three.
    Looking forward to seeing more. Definitely subscribing.

  • @the-pink-hacker
    @the-pink-hacker 9 หลายเดือนก่อน +1

    Creating and dealing with errors in Rust has always been difficult for me. Thanks to you, I know understand them a lot better. I'll definitely look into the thiserror and anyhow crates.

  • @user-zz6fk8bc8u
    @user-zz6fk8bc8u 9 หลายเดือนก่อน +1

    The best Rust videos on TH-cam. Amazing. Thank you so much for the videos and the time you take to make them.

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

    These videos are always great explanations and I learn something new everytime.

  • @coffeetimefun
    @coffeetimefun 9 หลายเดือนก่อน +3

    Come for the rust, stay for the category theory! Good pace by the way 😊

  • @Kameko-uq5wy
    @Kameko-uq5wy 9 หลายเดือนก่อน +2

    In the higher-level areas of my code, I like to separate errors (which now represent many processes) as being in two classes: recoverable and unrecoverable (which is a bit of a misnomer). Unrecoverable errors are when the code/program is missing some vital information, and, unless it's somehow fixed by something or that entire subsystem is reset, the program must fail. Recoverable errors are like I/O errors, where it's more like "This is a benign error that I can just try again at, but if it persists, then there might be a problem with the environment that the user should know about, which is why I'm telling you now."
    I also prototype with anyhow::Error, I just use it blindly everywhere in a module as I design it. Once I've built up the design, I go in, look at all possible errors, and design my error types properly, rather than trying to guess what I think my API might look like when it's done.
    I specifically do not represent an invalid program state in errors, as Rust makes invalid program states impossible. So if you wrote code that can have an invalid state, you're just writing buggy code and should remodel your design. Sometimes if you catch yourself writing an error, you can stop yourself to think "wait, do I really need to make this a runtime decision?"

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

    Sooo good explained: Love how you peak into architectural misshapes everybody should take to their heart when writing return types. One writes for the usage, and being sloppy on return types and even returning too little sometimes just frustrates the users, so some extra thought is always welcome :) ❤

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

    Clicked on the rust, pleasantly surprised by the haskell!

  • @hl2mukkel
    @hl2mukkel 9 หลายเดือนก่อน

    Amazingly well done videos, can't wait for more!

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

    I love the idea of having a safe program, but it really irritates me when I have a tree of functions that returns a result, and I have to set every single function to return a result. Maybe I'm just a bad at Rust though 😂

  • @eckelfresh
    @eckelfresh 9 หลายเดือนก่อน

    That is awesome! I learn more details about the mechanics behind Rust. And you have a very nice style.

  • @jacksonhenry1489
    @jacksonhenry1489 8 หลายเดือนก่อน

    I need more so glad I found your channel

  • @JoseLuisQuintana
    @JoseLuisQuintana 9 หลายเดือนก่อน

    Please keep that quality Rust content! Thanks for sharing!

  • @TheInspctrcat
    @TheInspctrcat 9 หลายเดือนก่อน

    One of the best channels about Rust lang

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

    So clear and easy to follow. Great explanation, thank you!

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

    This video finally fully cleared up the use of Result for me. Thank you!

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

    I saw this - and I thought: "WOW I NEEDED THIS I WISH I WAS SUBBED TO THIS BIG CHANNEL YEARS AGO". They I saw that I am subbed already.
    Then I saw that your channel is one of those small channels which I felt needed 20 hours to binge. Then I saw the comment underneath which also says the same T_T
    This channel will be huge. I'm calling it.

    • @Proprogrammer001
      @Proprogrammer001 9 หลายเดือนก่อน

      I am at 11:20. That blew my mind. Its SO crystal clear I actually had to pause.

    • @Proprogrammer001
      @Proprogrammer001 9 หลายเดือนก่อน

      The thing at 15:56 also blew my mind. What a video sheesh.

  • @SyamaMishra
    @SyamaMishra 9 หลายเดือนก่อน

    Great video on one of the more complex parts of Rust. Thanks so much!

  • @nathanoy_
    @nathanoy_ 9 หลายเดือนก่อน +2

    Awesome video, as always!
    You sir, are criminally undersubscribed.

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

    Great video (an channel)! Very well explained. You use some great examples.

  • @Galakyllz
    @Galakyllz 9 หลายเดือนก่อน

    This video was so good. Please, please create more videos. Thank you.

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

    Thanks for your content! ❤

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

    Great content, you explain it very clearly. Hope you continue with stuff like this

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

    That was really really good stuff. I’ve never used any of the error crates because I’ve always strived to handle/propagate errors before they hit main.
    Some notes that I think would have been very beneficial (albeit philosophically) is that errors and the result/option enums are there to represent invalid state.
    I think you are correct that None should be inferable, but the purpose of Err is to announce and detail what erroneous state has occurred. Take serde_json::Error the error is a enum but for relevant variants it contains line and column information. Great for syntax error but useless or EOF (empty json)
    The last thing IMHO is that not all errors should be recoverable. For example if you are converting a &[u8] to a string and a non-UTF8 character is provided perhaps you can gracefully handle the error but if recovery is impossible then failure should be defined by the program.
    Rust is a systems language an OS is not a guarantee. If failure is inevitable then provide relevant context before panic!(). I believe this is the reason why .unwrap and .expect panic on Err. How do you allocate E to T when the variable is expecting T. A case of UB for sure better to panic than let it hit memory

  • @tombil-certon
    @tombil-certon 9 หลายเดือนก่อน

    Very informative! Enjoyed the video

  • @Benfalk1982
    @Benfalk1982 9 หลายเดือนก่อน

    Fantastic rust videos my dude 👍

  • @batsdk
    @batsdk 9 หลายเดือนก่อน

    Good Video, Keep up the good work. Really like to see more videos like this

  • @theherk
    @theherk 9 หลายเดือนก่อน

    Very useful information and excellent production.

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

    Came back to the video after reading some more Rust…makes more sense now. Appreciate making this for us.

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

    Your rust videos are incredible 🎉

  • @paradoxfx
    @paradoxfx 8 หลายเดือนก่อน

    Very well explained. Thank you

  • @RakavyYuval
    @RakavyYuval 9 หลายเดือนก่อน

    Excllent content, learned quite a bit! Thanks

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

    Also of note: Because `Ok` would've been of the correct type to put into the `W` struct, you could also use `.map(Self)` in that case, like in the previous case... 👀

  • @AK-vx4dy
    @AK-vx4dy 9 หลายเดือนก่อน

    Very comprehensive video and good share of experience.

  • @warasilawombat
    @warasilawombat 9 หลายเดือนก่อน

    This is absolutely fantastic.

  • @gergelypaless5042
    @gergelypaless5042 9 หลายเดือนก่อน +8

    Love the 3blue1brown animations! Great video, keep it up. You've just earned one subscriber btw 😊

  • @bigskyhunter
    @bigskyhunter 9 หลายเดือนก่อน

    There is a really nice pattern that a Result can be used for even if it conveys the same amount of information as an option.
    fn

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

    This is so good!!

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

    I appreciate that you styled your animations after 3Blue1Brown - maybe using his graphics library? - excellently put, super well documented on screen, and interesting. Keep them coming!

  • @emilien.breton
    @emilien.breton 9 หลายเดือนก่อน +1

    Amazing video. Simple concepts on the surface with complex ideas sprinkled about. I love these types of videos.
    What resources would you recommend for learning type theory? The first chapter of the HoTT book flew over my head unfortunately.

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

    12:12 wow damn, thanks for the traversal tip, I did not know Rust has it🎉
    It’s very useful in cases when you actually don’t need to accumulate all potential errors from the collection and just fail when first occurred

  • @TheEnde124
    @TheEnde124 9 หลายเดือนก่อน

    Love the comparison to haskell! Haskell has many super cool and useful features.

  • @James-the-elder
    @James-the-elder 9 หลายเดือนก่อน

    This is more like Rust for Computer Science Students and I love it

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

    Unbelievably good video. New sub!! Please cover errors in more depth if you feel like it :)

  • @GiovanniCostagliola
    @GiovanniCostagliola 8 หลายเดือนก่อน

    Great contents!

  • @jrmoulton
    @jrmoulton 9 หลายเดือนก่อน

    So good. Crazy well done.

  • @CYBERNETIC-ANGEL
    @CYBERNETIC-ANGEL 28 วันที่ผ่านมา

    concise, easy to understand and straight to the point, you earned yourself a sub

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

    These explanations are high quality stuff.

  • @Yotanido
    @Yotanido 9 หลายเดือนก่อน +2

    "You're thinking: If only we were writing Haskell, then we could use do-notation in the Either monad"
    I understand this is a joke. I really do.
    But damn, I was literally constructing a comment in my head about how neat this is in Haskell...

    • @_noisecode
      @_noisecode  9 หลายเดือนก่อน +2

      So the real joke was that for you, the joke wasn't a joke? I wonder what Haskell typeclass THAT is

  • @AndreasGrois
    @AndreasGrois 9 หลายเดือนก่อน

    Btw: The "higher" crate has a macro that mimics Haskell's do-notation in Rust.

    • @_noisecode
      @_noisecode  9 หลายเดือนก่อน

      Neat! I hadn't heard of it. Even just poking through the documentation is (funny, and also) probably useful if you're curious about this stuff. I would venture to say I think I understand functors quite well, but the crate's docs for its Functor trait put it even more simply and eloquently than I could have: "A Functor lets you change the type parameter of a generic type." Good stuff.

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

    Coming from Scala, I found this to be really helpful insight into errors in Rust.

  • @astrakernel
    @astrakernel 9 หลายเดือนก่อน

    That's a wonderful video 😊

  • @Starwort
    @Starwort 9 หลายเดือนก่อน

    A little note at the end - Result can be freely destructured as Ok(foo) is an irrefutable pattern (due to the Err variant being impossible to construct), and (at least IIRC) the optimiser (possibly as a result of NVO?) will unwrap the result at binary level in this case as well

    • @_noisecode
      @_noisecode  9 หลายเดือนก่อน

      Result probably has the same size/alignment/ABI as T, so unwrapping is just a no-op at the machine code level: rust.godbolt.org/z/bzssYq57T

    • @Starwort
      @Starwort 9 หลายเดือนก่อน

      @@_noisecode yes, that's one of the things I'm saying - the other is that you are allowed to do it by the rules of *Rust* as well (e.g. Ok(true) and Ok(false) are typically bit-compatible with true and false (as long as E is 1 byte or smaller, and fits into NVO), but you aren't allowed to destructure them freely if E is not !)
      I see how the second part of my statement is confusing; I meant it is unwrapped _at all times_ - due, as you note, to the transparency of the ABI in this case

  • @BrazenNL
    @BrazenNL 9 หลายเดือนก่อน

    Excellent. Subbed.