It's sooo useful in Rust to read through and practice the Option, Result, and slice functions. They show up everywhere, and the standard library provides loads of useful functions.
This video was very insightful! Thank you for sharing, as someone new to rust, seeing all the Option and Result helper methods demonstrated with such simplicity is very helpful. I would have wrote match patterns all over the place instead because I didn’t know about these functions, thanks again !
Great video, as always :D One think which is also worth mentioning is that, you can implement `From` trait on your custom error type and use question mark operator. Example: ``` #[derive(Debug)] struct SummationError; impl From for SummationError { fn from(_: ParseIntError) -> Self { SummationError } } [...] fn sum_str_vec(strs: &[String]) -> Result { let mut acc = 0; for s in strs { acc += to_int(s)?; } Ok(acc.to_string()) } ```
Amazing exposition of the ways to handle simple errors like this one. I myself thought the introduction of the problem at 1:46 was a little too fast, but that became clear in immediately afterwards.
Thanks WombatGuru, and thanks for the feedback! I did blow through the explanation of the the program really quickly, I'll break it down a bit more next time!
Great video. I've only started learning Rust recently and just the other night a light bulb went on in my head as to the whole point of Result and unwrap. This video was therefore great timing for me.
Although I have been fiddling with programming for decades in my teens, when rust came out I was so bothered, like why all these unwraps and whatnot? Then I took computer science, and one of the modules taught about these optionables and nullables (yes, java) and also a custom "Result" wrapper we had to make. My professor hated nulls. It was hilarious because my other mod would use and abuse nulls. It was actually to teach the concepts of monads. Now when i watch this video, I laugh at myself because this video makes it so clear and easy what these things are.
My first exposure to Results and Options were at my internship where I was writing C# based on the railway-oriented programming paradigm. My goodness, I love not dealing or worrying about nulls, and Rust handles this form of error handling so beautifully.
I've . the best explanations on how to handle all these variants on the internet. I loved the progression in complexity, and how your can deal with errors with several different methods. This newbie appreciates
So helpful - I've seen all these variants in code (I'm a beginner) but couldn't keep them straight in my head. Seeing you build them up from ground level straightened it out for me. Thank you!
Wow. Great video! It gave me new tools to handle errors aside from 'match' and 'if let' It certainly will improve my future code readability. Thank you!
Great video! I was writing a toy program in rust to learn and went through almost the same evolution. It was actually frustrating because I didn't know if I should be returning result/option or using 'if let' vs match vs unwrap_or. I was assuming there is a correct (idiomatic) way, but couldn't ever figure out what that was.
Thanks for this very useful progression of code examples. As a complete beginner found it super useful to watch the video a few times before I could internalize the utility of Result and Option and the .ok , .unwrap and .err families of functions
My third day into Rust and watching your video and crust of rust’s video, I am very excited about Rust. Thank you and keep making more patterns related videos. It’s very helpful specially for intermediate/experienced developers to get started quickly.
been using similar concepts for year in Typescript via fpts. Now am getting into rust and am so glad I did because it's immediately clear to me what all this stuff is.
No matter how much you think you already know, you always learn from those kinds of videos. I didn't know about map_err and, guess what, ended up using it today 🙂 Keep up with the amazing work!
Great video! As the last step, you could implement `From` trait for the `SummationError` which would let you use the question mark operator without mapping the error.
Great content! Thank you very much. 2 quick suggestions: 1. May be use a teleprompter to avoid REM during the video 🙂 2. You might want to consider either adjusting the font size in VSCode terminal or use a separate terminal to run the code. It is near impossible to follow what's going on there.
Thanks Nexus, this is great feedback! Re: Looking offscreen, yeah this was a huge mistake that I noticed too late! Not doing that again haha. Re: terminal, yeah I'll look into this. I think I may have left the font size massive from something else I was doing, will look into toning it down a bit 🙃
@@irlshrek While I agree that the content is excellent and I certainly would like to see more, I also want him to have more quality videos so that they got even more views and enable him to spit out even more content. I sense a recursion ahead 🙂
this is great. would also be great to follow up with a part to on From and when it's appropriate. i've learned enough to know how to do that but not when it's appropriate or preferred
Thanks Hupa1a, cool to see that folks enjoy the format. I really having one core piece of code, then changing it slightly many times to demonstrate different concepts
Love your videos, but one small point of improvement; use #[test] functions instead of using main for testing. Test functions are really useful for just trying out stuff, and the examples they provide dont need to be deleted just to make room for "better" code
Thanks for the feedback! Yeah this would have made sense - I've been relentless about eliminating as much prerequisite knowledge as possible, maybe to a fault. You could certainly argue that writing tests is reasonable prerequisite knowledge.
Thanks again for another great video. It has definitely improved my confidence in knowing how to read and write Rust code. Looking forward to more awesome content.
ปีที่แล้ว +1
Really great video about the subject. Thanks a lot!!!
thanks! it sounds like many folks like the sound of the keyboard, so I actually put a mic up to it in the "Rust vs 7 Languages" video. Might try to do that more in the future.
Thanks Todsaporn, I'll do more like this. I also plan to do some kind of "Crate Hall of Fame" series where we tour some of the more ubiquitous crates like the ones you mentioned
Thank you for a video! Whats the best way to pick up this programming language? The learning curve is quite steep 😮 Even to develop a basic CRUD app along with Actix, makes a headache?
Thanks Arturs! I think the best way is to come up with a project (one that might be easy for you to build in some other language) and build it in Rust. I agree the learning curve is a bit steep but for many people it is worth it. I think a basic actix CRUD app is fairly straightforward (relatively speaking) and is probably a good place to start.
Yes, he could, but that's introducing a new concept (type conversions) into the mix. Also: MapError is the functional pattern to the "From/Into" concept.
likely the most important rust tutorial here. If you don't get Option and Result use cases down, you're won't make it... Something I just picked up from this one why all the conversion functions (between option and result) exist, which is mainly the ? shortcut needing to match with function result. I had not actually got that up to this point. Not doing much hands on yet though... This should be part of the day 1 training in Rust.
First of all, thanks for sharing this content. I'm a C++ coder, highly interested in Rust. Very helpful stuff. What I don't get at first glance is: When an error happens and we have a Result as a return value, is the error returned instantly without needing to explicitly "return" it? Does Rust handle this for us? Because I would expect to do things like "return None, Error" in terms of pseudocode.
Also for people using something like dyn Error or the anyhow crate: `map_err(Into::into)` converts into those types on your return statement (where the ? operator doesn't work).
Such a useful video. I was having a hard time figuring out converting between option/results or different result errors, so my code was littered with is_err and is_some, if not just unwrap().unwrap().unwrap() and a prayer. map_err was one function I never checked because something that starts with the word "map" isn't something I'd expect to be able to use to rewrite an error. I think I've removed every unchecked unwrap (I still use is_some in some special cases) and normalized all my errors. Only took about 20-30 minutes.
9:20 I would use the previous variant since it makes it clear I just don't add anything to accum if there is an error. This way I'm adding something which might be zero. It's not as obvious and maybe even less performant.
The complexity progression through the video is super helpful, great format, you should do more like this one.
Thanks, very happy the format worked for you! Will definitely create more.
It's sooo useful in Rust to read through and practice the Option, Result, and slice functions. They show up everywhere, and the standard library provides loads of useful functions.
💯 agree!
Clicked on video blazingly fast
Me too
Same
As a rust beginner, I've now watched this video about 6 times over the course of the last week. It's an excellent reference! Thanks! 🙏🏼
love this!! glad it's been valuable!
This video was very insightful! Thank you for sharing, as someone new to rust, seeing all the Option and Result helper methods demonstrated with such simplicity is very helpful.
I would have wrote match patterns all over the place instead because I didn’t know about these functions, thanks again !
Great Jaime, I'm really happy you found it valuable! Thanks for watching!
Great video, as always :D One think which is also worth mentioning is that, you can implement `From` trait on your custom error type and use question mark operator.
Example:
```
#[derive(Debug)]
struct SummationError;
impl From for SummationError {
fn from(_: ParseIntError) -> Self {
SummationError
}
}
[...]
fn sum_str_vec(strs: &[String]) -> Result {
let mut acc = 0;
for s in strs {
acc += to_int(s)?;
}
Ok(acc.to_string())
}
```
Amazing exposition of the ways to handle simple errors like this one. I myself thought the introduction of the problem at 1:46 was a little too fast, but that became clear in immediately afterwards.
Thanks WombatGuru, and thanks for the feedback! I did blow through the explanation of the the program really quickly, I'll break it down a bit more next time!
Great video. I've only started learning Rust recently and just the other night a light bulb went on in my head as to the whole point of Result and unwrap. This video was therefore great timing for me.
Nice thisisscotts! Really happy you found it valuable!
Although I have been fiddling with programming for decades in my teens, when rust came out I was so bothered, like why all these unwraps and whatnot?
Then I took computer science, and one of the modules taught about these optionables and nullables (yes, java) and also a custom "Result" wrapper we had to make. My professor hated nulls. It was hilarious because my other mod would use and abuse nulls.
It was actually to teach the concepts of monads.
Now when i watch this video, I laugh at myself because this video makes it so clear and easy what these things are.
One of the best videos I've seen about these for someone like me that's just learning Rust
My first exposure to Results and Options were at my internship where I was writing C# based on the railway-oriented programming paradigm. My goodness, I love not dealing or worrying about nulls, and Rust handles this form of error handling so beautifully.
I've . the best explanations on how to handle all these variants on the internet. I loved the progression in complexity, and how your can deal with errors with several different methods. This newbie appreciates
thank you, really happy you got something out of it!
So helpful - I've seen all these variants in code (I'm a beginner) but couldn't keep them straight in my head. Seeing you build them up from ground level straightened it out for me. Thank you!
Great density of information in this video
Thanks Matthew!
Wow. Great video! It gave me new tools to handle errors aside from 'match' and 'if let' It certainly will improve my future code readability. Thank you!
Thanks, glad you found it valuable!
Thanks, the question mark was extremely helpful to replace some of my now redundant match clauses.
nice, really happy you got something out of it!
Thank me so much for helping me through handling errors in Rust. You deepened my knowledge 🙌
Really helpful video to understand t OK(), ? and map() functions. Please keep making such videos.
Great video! I was writing a toy program in rust to learn and went through almost the same evolution. It was actually frustrating because I didn't know if I should be returning result/option or using 'if let' vs match vs unwrap_or. I was assuming there is a correct (idiomatic) way, but couldn't ever figure out what that was.
Thanks for this very useful progression of code examples. As a complete beginner found it super useful to watch the video a few times before I could internalize the utility of Result and Option and the .ok , .unwrap and .err families of functions
My third day into Rust and watching your video and crust of rust’s video, I am very excited about Rust. Thank you and keep making more patterns related videos. It’s very helpful specially for intermediate/experienced developers to get started quickly.
I've definitely been overusing Option when I should be using Result, thanks for your examples.
nice, really happy the video helped!
Honestly, i couldn't get my head wrap around on these error handlings before but not anymore . Thank you so much!!!
Great Video. I wish there were more people making videos about Rust.
thanks! and me too.
This really helped me a lot. the functions and containers are so similar it's nice to have a run through these patterns.
Thanks for putting this out. This was very insightful for newbies like me. 🙏
been using similar concepts for year in Typescript via fpts. Now am getting into rust and am so glad I did because it's immediately clear to me what all this stuff is.
Good explanation about how to elegantly deal with unexpected behaviours! Thanks for that!!
thanks, glad you found it valuable!
No matter how much you think you already know, you always learn from those kinds of videos. I didn't know about map_err and, guess what, ended up using it today 🙂
Keep up with the amazing work!
Nice, glad you got something useful out of it! Thanks for the kind words!
I needed map_err yesterday and this popped up on suggestions today. Guess I'll fix that unwrap today!
Thank you!!!! Great explanations with easy to understand examples! More please :)
Great, glad you got something out of it! More on the way!
Insanely good and concise explanation. Thanks. You definitely know how to explain things.
Thanks, really happy you found it valuable!
Great video! As the last step, you could implement `From` trait for the `SummationError` which would let you use the question mark operator without mapping the error.
thank you, and great point!
That’s really well explained. I’m sharing it to a friend that want to learn Rust.
Thanks Robin, and thanks for sharing it!
Great content! Thank you very much.
2 quick suggestions:
1. May be use a teleprompter to avoid REM during the video 🙂
2. You might want to consider either adjusting the font size in VSCode terminal or use a separate terminal to run the code. It is near impossible to follow what's going on there.
id rather he focus on spitting more of these videos out!
Thanks Nexus, this is great feedback!
Re: Looking offscreen, yeah this was a huge mistake that I noticed too late! Not doing that again haha.
Re: terminal, yeah I'll look into this. I think I may have left the font size massive from something else I was doing, will look into toning it down a bit 🙃
@@irlshrek While I agree that the content is excellent and I certainly would like to see more, I also want him to have more quality videos so that they got even more views and enable him to spit out even more content. I sense a recursion ahead 🙂
this is great. would also be great to follow up with a part to on From and when it's appropriate. i've learned enough to know how to do that but not when it's appropriate or preferred
Thanks Madeline, I'll add From into() the video idea list!
I’m new to Rust. Awesome video, super useful. Thank you!
Great, glad you got something out of it! 😎
I wish I had this video when I was first starting out with Rust. Great video!
Great video. I like how it is structured
Thanks Hupa1a, cool to see that folks enjoy the format. I really having one core piece of code, then changing it slightly many times to demonstrate different concepts
That was excellent details on Result and Option. Thank you!
thanks really happy you found it valuable!
In that use case, you can use .or(SummationError) instead of .map_err(|_| SummationError) method.
Love your videos, but one small point of improvement; use #[test] functions instead of using main for testing. Test functions are really useful for just trying out stuff, and the examples they provide dont need to be deleted just to make room for "better" code
Thanks for the feedback! Yeah this would have made sense - I've been relentless about eliminating as much prerequisite knowledge as possible, maybe to a fault. You could certainly argue that writing tests is reasonable prerequisite knowledge.
Loved the video, it was extremely insightful and easy to digest for a beginner like me. I hope you make more of these!
This is super helpful, I didn't know about that last one you showed. Thank you!!
Glad you found it valuable, thanks for watching Chris!
Brilliantly structured, getting me excited to get started with Rust!
thank you, very happy it fueled your fire to learn Rust!
Was just reading about that in the rust book two days ago. Great timing!
Nice!
This is a great video! The example and the explanation done extremely well! I like how you explain hard things.
Excellent video! Would love to see more pattern videos like this to add to the toolbox
Thanks JammyJ, more are on the way (I'm a poet and I didn't know it)!
Great video! Learnt few new things, please keep making them
Thanks gorudonu, more to come!
Wow, that was a useful video compressed in a few minutes. Thanks!
thanks, really happy it was helpful!
Nice explanation for monads from functional languages. Keep up! Thanks!
Thanks for watching Artem! I managed to do it without using the word "monad" - not sure if that's a good or a bad thing 🙃
These containers are so fundamental to the language.
Agree 💯
This was very interesting and very clearly explained. Thank you
thanks, glad you found it valuable!
Thanks again for another great video. It has definitely improved my confidence in knowing how to read and write Rust code. Looking forward to more awesome content.
Really great video about the subject. Thanks a lot!!!
thanks glad you got something out of it!
BEST VIDEO !!! THIS WAS THE ONLY THING THAT KEPT ME FROM UNDERSTANDIGN RUST !
glad you found it valuable!
Great video. Bookmarked it. Will likely go back to it many time in the future ;) Thanks
Thanks Miriam, I hope it provides evergreen value for you!
Valuable information! Look forward to your videos always! As I’m currently learning rust
Thanks drama, glad you found it valuable!
That keyboard sound on 2x, music to my ears!
thanks! it sounds like many folks like the sound of the keyboard, so I actually put a mic up to it in the "Rust vs 7 Languages" video. Might try to do that more in the future.
Great explanation! Thanks a lot!!!
Thanks. This practice examples are great!
Thanks preeby, glad you found it valuable!
Nice colorscheme, can you tell the name of this one?
Exactly what I needed, thanks!
great, glad you found it valuable!
The best! I need more of this please! BTW, it would be more handy if you mention thiserror and anyhow in the end. 👍👍👍
Thanks Todsaporn, I'll do more like this. I also plan to do some kind of "Crate Hall of Fame" series where we tour some of the more ubiquitous crates like the ones you mentioned
Each video I watch from this channel makes me less angry with Rust. 🤝
nice! mission accomplished 😎
A lot of useful details. Well deserved subscription ✌
Thanks, glad you found it valuable!!
This video was incredibly well made, it is hard to match. Thank you for the great content.
thanks so much for the kind words!
Just brilliant. Thank you so much.
Thanks!
rly rly great I loving all rust lectures form awesome people here in yt
Thanks glad you liked it!
What theme do you use in vsc?
Thank you for a video!
Whats the best way to pick up this programming language?
The learning curve is quite steep 😮
Even to develop a basic CRUD app along with Actix, makes a headache?
Thanks Arturs! I think the best way is to come up with a project (one that might be easy for you to build in some other language) and build it in Rust. I agree the learning curve is a bit steep but for many people it is worth it. I think a basic actix CRUD app is fairly straightforward (relatively speaking) and is probably a good place to start.
Great video! Would you make a video about 'static and how to work with that?
Thanks Aditya! I'll put 'static on the video idea list!
Excellent video! Great tempo.
Thanks Eric, glad you found it valuable!
Very insightful content! Thank you for this.
Thanks for watching Ed!
This is a such a good informative video, i wish i found it sooner!
You can remove the call to map_err at the end by implementing From for SummationError
Yes, he could, but that's introducing a new concept (type conversions) into the mix. Also: MapError is the functional pattern to the "From/Into" concept.
It would be nice if those 10 patterns got indexed or simply numbered in the video :)
Thanks for the feedback, I may add numbers / titles in the future!
that was great! This is exactly something I struggled with as a Rust beginner but coming from other languages.
Thanks Telflora!
It's so nice !!!! pretty much thanks to your share!!!
Thanks for the kind words and thanks for watching!
likely the most important rust tutorial here.
If you don't get Option and Result use cases down, you're won't make it...
Something I just picked up from this one why all the conversion functions (between option and result) exist, which is mainly the ? shortcut needing to match with function result. I had not actually got that up to this point. Not doing much hands on yet though...
This should be part of the day 1 training in Rust.
First of all, thanks for sharing this content. I'm a C++ coder, highly interested in Rust. Very helpful stuff. What I don't get at first glance is: When an error happens and we have a Result as a return value, is the error returned instantly without needing to explicitly "return" it? Does Rust handle this for us? Because I would expect to do things like "return None, Error" in terms of pseudocode.
Maaaan, really throughout. WHat a nice video, wow. I'm impressed. THanks
thank you, glad you got something out of it!
Also for people using something like dyn Error or the anyhow crate: `map_err(Into::into)` converts into those types on your return statement (where the ? operator doesn't work).
Very helpful, thanks!
thanks, glad you got something out of it!
Which IDE are you using?
@codetothemoon there is another stage you can do after your last stage 10, which shows the beauty of rust and makes everything fit nicely
Such a useful video. I was having a hard time figuring out converting between option/results or different result errors, so my code was littered with is_err and is_some, if not just unwrap().unwrap().unwrap() and a prayer. map_err was one function I never checked because something that starts with the word "map" isn't something I'd expect to be able to use to rewrite an error. I think I've removed every unchecked unwrap (I still use is_some in some special cases) and normalized all my errors. Only took about 20-30 minutes.
thanks for this useful tutorial
glad you found it valuable, thanks for watching!
this cleared things up thanks
9:20 I would use the previous variant since it makes it clear I just don't add anything to accum if there is an error. This way I'm adding something which might be zero. It's not as obvious and maybe even less performant.
Great video! Really good and understandable structure.
Thanks mivoe99, glad you found it valuable!
Pretty good explanation, I subscribed because of this video.
Great, didn't know Option and Result share this functionality
Great video. Thanks
thanks for watching, glad you got something out of it!
Good intro, would be even better if Boxed errors and custom error types were mentioned at the end. Nice explanations!
Thanks Dr Maybe, yeah maybe I should have covered those as well. Maybe in a future video!
omg this was so useful! Thank you for good videos :)
very well explained!
thank you, glad you got something out of it!
Nice video! Which plugins do you use?
Thanks, great explanation :)
thanks for watching, glad you found it valuable!
awesome. Thank you man!
This was an awesome video. Please do more