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.
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
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.
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.
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
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!
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.
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??
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 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
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.
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?
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.
@ 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?
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 😅.)
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?
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.
@@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.
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++)
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.
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.
"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.
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}"); }
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
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
📝 Get your *FREE Rust cheat sheet* : www.letsgetrusty.com/cheatsheet
Didn't the russian propagandists say that there is no panic :)
Probably their error handling is not well implemented.
Great content. Coming from mainly Fortran and a bit C++, Rust is like heaven.
You're a goddamn hero! Fortran is not for the faint of heart.
Your series basically flattened the learning curve of rust.
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.
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
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.
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.
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
You need more subscribers! Your content is amazing
Appreciate the support Zach!
Love your content, it's makes it clear and easier than any other sources that i used to learn rust, keep it up
I watch these videos first and then read the chapter. Has been working great.
These videos are brilliant, thanks for your hard work putting them together.
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!
Concise and high quality. Thanks.
Thank you so much for all your videos. High quality content !
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?
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.
Your videos are amazing, keep up the good work
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??
Your content is amazing
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 :)
Ah yes combinators are a good topic for a video. Will make one eventually but not for a while.
@@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
Spasibo wam balshoy!!
Why does my Result causes compilation error stating "expected 0 generic arguments" ?
Love the content and ALSO love the background :)
This helped so much
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.
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?
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.
Great video. Thanks
Thanks for this tutorial
Loved it
thanks
you missed to explain the syntax/meaning of | error | function/closure
we was reading from `f` so why that needed to be converted to mut 10:43?
Glad I found this
A follow up video on thiserror and anyhow would be good
@ 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?
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 😅.)
I'm waiting for a videos about data structures :)
how did u get the inline parameters to show up btw nice videos keep it up
I installed the rust-analyzer VS code extension: marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer
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?
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.
@@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.
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++)
Yeah I hear you Sahil. Rust definitely makes error handling more tedious. You can use unwrap() to avoid error handling while prototyping code.
Sounds like a code smell to me if you don't know which errors can occur and just catch 'em all.
@@31redorange08 python try except go brrr
It allows you to catch specific errors you would like!
@@Terroidit allows you to, but you can easily just catch them all.
🏳️🌈?
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.
Bogdan is a Romanian name. Are you Romanian-American?
It was a lot of stuff packed in 16 minutes. I need to digest it.
I assume that when the File instance gets Dropped, it closes the file. In other languages, the programmer must explicitly close the file.
That's correct. The borrow checker knows when a file is no longer needed and drops it, which causes the handle to close.
Can you teach Serde?
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.
"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.
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}");
}
whats the outro music?
soundcloud.com/rantalaofficial/heroes
@@letsgetrusty thanks a lot
but why are you using ...... default aah linux theme, use catpuccin
So what country ya from, Bogdan?
Ukraine
@@letsgetrusty Praying for you right now 🙏
The audio and video is kinda out of sync.
It's sad that I can only give this video 1 like
Ahhhh Rust is hard !!! from a js developer
Your flag is backwards.
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
YOU FORGOT TO TURN ON THE LETS GET RUSTY SIGN!!!!
I heard it isn't a real programming language if JetBrain doesn't have an IDE for it
www.jetbrains.com/rust/
@@letsgetrusty That's a plugin boi
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
@@GolangDojo A good read 😉 fasterthanli.me/articles/i-want-off-mr-golangs-wild-rid
@@GolangDojowelp, they made an ide for it
Thanks for the lesson. (FYI your U.S. flag is displayed backwards! 🫡)