Error Handling in Rust

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

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

  • @letsgetrusty
    @letsgetrusty  3 ปีที่แล้ว +7

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

    • @romanstingler435
      @romanstingler435 2 ปีที่แล้ว

      Didn't the russian propagandists say that there is no panic :)
      Probably their error handling is not well implemented.

  • @uovo
    @uovo 2 ปีที่แล้ว +19

    Your series basically flattened the learning curve of rust.

  • @albertz0
    @albertz0 3 ปีที่แล้ว +74

    Great content. Coming from mainly Fortran and a bit C++, Rust is like heaven.

    • @ShimoriUta77
      @ShimoriUta77 5 หลายเดือนก่อน +2

      You're a goddamn hero! Fortran is not for the faint of heart.

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

    the book is so verbose that reading the entire book became a pain for me. your videos literally became my life saviour by helping me continue learning Rust without taking the pain the book has to give! Thank You Very much for your videos!

  • @اشکانمحمدی-ز1ث
    @اشکانمحمدی-ز1ث 2 ปีที่แล้ว +19

    I expected to see the usual try-catch blocks that we are mostly used to but Rust has exceeded the expectations that I had in mind before watching this video. I have mostly worked with js and python. It is very difficult to deal with errors in both languages.

  • @KyleHarrisonRedacted
    @KyleHarrisonRedacted ปีที่แล้ว +16

    This was incredibly useful, for such an ambiguous and huge topic you’ve really booked it down to simply approaches and even answered by accident a bunch of questions I had about Rust in general, and boiled that down to less than 17min

  • @CalifornianViking
    @CalifornianViking 2 ปีที่แล้ว +12

    Bogden, your videos are great. I have read the Rust book, but find that your videos are a lot easier to follow.
    You are asking about what other content to cover. A lot of people that start using Rust come from class and object oriented languages such as C#, Java, and TypeScript. It would be great to have videos about how to architect your code and comparing how things were done in the other languages to how it is done in Rust. One example is polymorphism which is not obvious since there is no class hierarchy.

  • @lardycake
    @lardycake 2 ปีที่แล้ว +10

    Just want to say thank you for all of your vids. I'm a senior software engineer with experience in most of this kind of stuff in other languages and you go at exactly the right pace to be able to pick up Rust quickly.

  • @miro42344234
    @miro42344234 ปีที่แล้ว +2

    watching this playlist while reading the book, I got to say, job really well done, makes everything much clearer and easier to grasp, which says a lot, considering the fact that the book is well written

  • @pygeekrfoo820
    @pygeekrfoo820 ปีที่แล้ว +2

    I watch these videos first and then read the chapter. Has been working great.

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

    That ‘!’ That comes after panic looks so gorgeous

  • @katarsloto4223
    @katarsloto4223 3 ปีที่แล้ว +19

    Love your content, it's makes it clear and easier than any other sources that i used to learn rust, keep it up

  • @ZachPeters
    @ZachPeters 3 ปีที่แล้ว +48

    You need more subscribers! Your content is amazing

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +1

      Appreciate the support Zach!

  • @ccprt1275
    @ccprt1275 3 ปีที่แล้ว +8

    These videos are brilliant, thanks for your hard work putting them together.

  • @sakuranooka
    @sakuranooka 3 ปีที่แล้ว +4

    So, in the last example ("Guess"), if, instead of panicking, I wanted to create and return a Result structure, what would the code look like?

    • @Gramini
      @Gramini ปีที่แล้ว +3

      Instead of panicking you'd return an Err("Invalid guess") and instead of returning a Guess on success, wrap in in an Ok(). Then reflect the new return type in the signature: -> Result
      Instead of the error being a String/&str you can use a custom error type.

  • @goodwish1543
    @goodwish1543 2 ปีที่แล้ว +3

    Concise and high quality. Thanks.

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

    Thank you so much for all your videos. High quality content !

  • @mohanaggarwal4058
    @mohanaggarwal4058 2 ปีที่แล้ว +2

    Great video!! 👍, I want to ask u a general question, as u might know js/ts and there we have try-catch-finally blocks, safe navigation operator and nullish coalescing operator that helps the code to be more safer, as a rustacean how do u feel about error handling in rust and js, and what do u think which one is actually better??

  • @tanuvishu
    @tanuvishu 2 ปีที่แล้ว +2

    Your videos are amazing, keep up the good work

  • @myhendry
    @myhendry 3 ปีที่แล้ว +2

    Hi Bogdan, im learning Rust. I love your content! I came across combinators (ok_or, unwrap_or, ...) in Rust. I don't know which is applicable for different cases. hope you will release a video to guide us on this. thanks :)

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +6

      Ah yes combinators are a good topic for a video. Will make one eventually but not for a while.

    • @myhendry
      @myhendry 3 ปีที่แล้ว +1

      @@letsgetrusty coming from a Javascript background, what is confusing to me about Rust are the combinators and Traits. I understand combinators and Traits are meant to help programmers. for a newcomer though, it is hard to know which type of combinator and Trait to use in which case. I wonder how many Rust learners face this situation as well

  • @dhiliph98
    @dhiliph98 2 ปีที่แล้ว +1

    Hello Bogdan, at 15:40, you created a public value() method so that an instance of Guess struct cannot access the underlying value property. But we still seem to have access to the value property from the instance variable. Am I understanding it right or confusing it with classic OOP?

    • @v1k70r99
      @v1k70r99 2 ปีที่แล้ว +2

      In the video "Structs in Rust" he explains that even if a struct is set to be public, all fields inside the struct are private by default. This can be changed by adding "pub" in front of the field.

  • @benosambinu2473
    @benosambinu2473 2 ปีที่แล้ว

    Why does my Result causes compilation error stating "expected 0 generic arguments" ?

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

    we was reading from `f` so why that needed to be converted to mut 10:43?

  • @shfunky
    @shfunky 2 ปีที่แล้ว

    Spasibo wam balshoy!!

  • @matthiasdebernardini3388
    @matthiasdebernardini3388 2 ปีที่แล้ว

    A follow up video on thiserror and anyhow would be good

  • @yasserelidrissiameur4723
    @yasserelidrissiameur4723 3 ปีที่แล้ว +1

    Your content is amazing

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

    As of 05/14/2024 "when I attempted to code along, your (9:52) line 6 and line 17 doesn't work anymore. miss-matched type error of when now it needs to be so, seems like people who watch this as of me writing this need to ignore that example.

  • @pynchia4119
    @pynchia4119 2 ปีที่แล้ว +1

    you missed to explain the syntax/meaning of | error | function/closure

  • @itscozy6279
    @itscozy6279 3 ปีที่แล้ว +1

    how did u get the inline parameters to show up btw nice videos keep it up

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +2

      I installed the rust-analyzer VS code extension: marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer

  • @fenilli
    @fenilli 3 ปีที่แล้ว

    @ 15:44, do you think making a Enum with ValidGuess(i32) and InvalidGuess where new returns a instance of that Enum would be better for handling a validation state instead?

    • @mateusoliveira2776
      @mateusoliveira2776 2 ปีที่แล้ว +1

      If you want to return something to the caller that helps it deal with a failure, that sounds like what he said about error propagation. So, maybe, returning a Result would suffice? This way the caller can handle it, just like with your suggestion of an Enum, since there are just two cases, one that is Ok and one that is an Error... (I know I'm very late on the answer, just putting this here so new people can see, I guess 😅.)

  • @elmondo.
    @elmondo. 3 ปีที่แล้ว

    Thanks for this tutorial

  • @miriamramstudio3982
    @miriamramstudio3982 ปีที่แล้ว

    Great video. Thanks

  • @luv2stack
    @luv2stack 2 ปีที่แล้ว

    This helped so much

  • @ochudi
    @ochudi 2 ปีที่แล้ว

    Can you teach Serde?

  • @timothyvandyke9511
    @timothyvandyke9511 3 ปีที่แล้ว

    Glad I found this

  • @DavidJames-hg5tj
    @DavidJames-hg5tj 2 ปีที่แล้ว

    There is a whining noise in the background. Since I can hear it on both a Linux computer and an Android phone it has to part of this series of videos. I understand you-tube has an option to remove background noise.

  • @sahilverma4077
    @sahilverma4077 3 ปีที่แล้ว +3

    I like the implementation of Result enum but I still miss try-catch, it feels so like home to me, I mean you don't need to know much about the error or anything you can just provide a case and if it doesn't work you have a catch that will run for sure, and we can even have multiple lines in try
    cause I think it's tedious to do use Result everytime and the other alternatives are not at all reliable, I liked the lambda somewhat but we still have to manage all the errors together, and sorry if I'm talking naively, I'm from a java background and am learning rust only for web assembly (and i hate C++)

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +5

      Yeah I hear you Sahil. Rust definitely makes error handling more tedious. You can use unwrap() to avoid error handling while prototyping code.

    • @31redorange08
      @31redorange08 3 ปีที่แล้ว +1

      Sounds like a code smell to me if you don't know which errors can occur and just catch 'em all.

    • @Terroid
      @Terroid 2 ปีที่แล้ว

      @@31redorange08 python try except go brrr
      It allows you to catch specific errors you would like!

    • @Anon.G
      @Anon.G ปีที่แล้ว

      ​@@Terroidit allows you to, but you can easily just catch them all.

    • @gustavojoaquin_arch
      @gustavojoaquin_arch ปีที่แล้ว

      🏳️‍🌈?

  • @Galakyllz
    @Galakyllz 2 ปีที่แล้ว

    I'm confused why you need a mutable File to read_to_string, but you can use an _immutable_ File to read_to_end? Why must it be immutable in one instance but not the other?

    • @Gramini
      @Gramini ปีที่แล้ว +2

      It must be mutable in both cases if I'm not mistaken. The documentation for read_to_end says it wants a mutable File: fn read_to_end(&mut self, buf: &mut Vec)
      The reason why it has to be mutable although you're only reading is because reading changes the cursor/position of the file. The file itself might not be mutable, but the variable and data on of the program is.

    • @Galakyllz
      @Galakyllz ปีที่แล้ว +1

      @@Gramini You're absolutely right. I saw a tutorial that seemed to *not* mark the variable as mutable, but now I can't remember where I saw it. Looking at the documentation of File, it's clear that both functions require a mutable reference to self (for the reasons you mentioned, very likely).
      Thanks for the reply. Have a great day.

  • @paviad
    @paviad 2 ปีที่แล้ว +1

    Love the content and ALSO love the background :)

  • @initfunction6961
    @initfunction6961 3 ปีที่แล้ว

    I'm waiting for a videos about data structures :)

  • @jabuci
    @jabuci 2 ปีที่แล้ว

    It was a lot of stuff packed in 16 minutes. I need to digest it.

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

    Loved it

  • @rl1111rl
    @rl1111rl 2 ปีที่แล้ว

    unwrap_or_else() seems convoluted. I'm sure the Rust designers have their reasons but I think even a modern systems level language could be more a bit more elegant.

    • @yondaime500
      @yondaime500 2 ปีที่แล้ว +3

      "or_else" lets you specify a lazily-evaluated call that will run to create a valid result or option only if needed, unlike "or", which always generates the valid value regardless of whether it is needed. So you can use "or" when the default value is a constant or some value you already have available, and "or_else" when you actually need to do some work to generate it.
      In either case, the value after this call will always be Ok/Some, so you can prepend "unwrap_" to get it right away while you are sure it will not panic. If you had to call unwrap separately, it would be incorrectly flagged by the linter as a place where the code might panic.

    • @Gramini
      @Gramini ปีที่แล้ว +1

      If you want somethin to run only in case of an error you can also use if let, as in
      if let Err(error) = might_give_an_error() {
      println!("There's an error: {error}");
      }

  • @ricardorien
    @ricardorien ปีที่แล้ว

    thanks

  • @mztikk
    @mztikk 3 ปีที่แล้ว

    whats the outro music?

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +2

      soundcloud.com/rantalaofficial/heroes

    • @mztikk
      @mztikk 3 ปีที่แล้ว

      @@letsgetrusty thanks a lot

  • @michaelnajera7958
    @michaelnajera7958 3 ปีที่แล้ว

    So what country ya from, Bogdan?

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +2

      Ukraine

    • @Firerent
      @Firerent 2 ปีที่แล้ว +1

      @@letsgetrusty Praying for you right now 🙏

  • @rl1111rl
    @rl1111rl 2 ปีที่แล้ว

    I assume that when the File instance gets Dropped, it closes the file. In other languages, the programmer must explicitly close the file.

    • @Gramini
      @Gramini ปีที่แล้ว

      That's correct. The borrow checker knows when a file is no longer needed and drops it, which causes the handle to close.

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

    but why are you using ...... default aah linux theme, use catpuccin

  • @foobar1269
    @foobar1269 2 ปีที่แล้ว

    It's sad that I can only give this video 1 like

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

    Bogdan is a Romanian name. Are you Romanian-American?

  • @JasonIvey-o2t
    @JasonIvey-o2t ปีที่แล้ว

    The audio and video is kinda out of sync.

  • @imnemo2327
    @imnemo2327 2 ปีที่แล้ว

    Ahhhh Rust is hard !!! from a js developer

  • @dreamtheater_92
    @dreamtheater_92 ปีที่แล้ว

    Your flag is backwards.

  • @sheepsushis5720
    @sheepsushis5720 2 ปีที่แล้ว

    YOU FORGOT TO TURN ON THE LETS GET RUSTY SIGN!!!!

  • @GolangDojo
    @GolangDojo 3 ปีที่แล้ว +1

    I heard it isn't a real programming language if JetBrain doesn't have an IDE for it

    • @letsgetrusty
      @letsgetrusty  3 ปีที่แล้ว +8

      www.jetbrains.com/rust/

    • @GolangDojo
      @GolangDojo 3 ปีที่แล้ว

      @@letsgetrusty That's a plugin boi

    • @ozanmuyes
      @ozanmuyes 3 ปีที่แล้ว +1

      To be honest I stopped using JetBrains products right after I moved from PHP and let me tell you it was one of my radical life decisions and it was a blessing for me

    • @ozanmuyes
      @ozanmuyes 3 ปีที่แล้ว

      @@GolangDojo A good read 😉 fasterthanli.me/articles/i-want-off-mr-golangs-wild-rid

    • @everythingtube172
      @everythingtube172 11 หลายเดือนก่อน

      @@GolangDojowelp, they made an ide for it

  • @koenigsbier50
    @koenigsbier50 2 ปีที่แล้ว

    I liked the video but really too bad that you're stopping at some specific chapters and you say "this is in chapter xx, we will cover that another time".
    I was expecting a video that covers entirely error handling. If the video is restricted to some specific chapters I might as well go read the book directly...
    This is just a friendly suggestion. I like your content but that would be great if you could make some videos a bit different than the Rust book

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

    Thanks for the lesson. (FYI your U.S. flag is displayed backwards! 🫡)