Тёмный

Rust's Most Important Containers 📦 10 Useful Patterns 

Code to the Moon
Подписаться 69 тыс.
Просмотров 116 тыс.
50% 1

A walkthrough and explanation of 10 useful patterns involving Rust's Option and Result containers.
-
Stuff I use to make these videos - I absolutely love all of these products. Using these links is an easy way to support the channel, thank you so much if you do so!!!
Camera: Canon EOS R5 amzn.to/3CCrxzl
Monitor: Dell U4914DW 49in amzn.to/3MJV1jx
Lens: Sigma 24mm f/1.4 DG HSM Art for Canon EF amzn.to/3hZ10mz
SSD for Video Editing: VectoTech Rapid 8TB amzn.to/3hXz9TM
Microphone: Rode NT1-A amzn.to/3vWM4gL
Microphone Interface: Focusrite Clarett+ 2Pre amzn.to/3J5dy7S
Tripod: JOBY GorillaPod 5K amzn.to/3JaPxMA
Keyboard: Redragon Mechanical Gaming Keyboard amzn.to/3I1A7ZD
Mouse: Razer DeathAdder amzn.to/3J9fYCf
Computer: 2021 Macbook Pro amzn.to/3J7FXtW
Caffeine: High Brew Cold Brew Coffee amzn.to/3hXyx0q
More Caffeine: Monster Energy Juice, Pipeline Punch amzn.to/3Czmfox
Building A Second Brain book: amzn.to/3cIShWf

Наука

Опубликовано:

 

21 окт 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 344   
@gdnight
@gdnight Год назад
The complexity progression through the video is super helpful, great format, you should do more like this one.
@codetothemoon
@codetothemoon Год назад
Thanks, very happy the format worked for you! Will definitely create more.
@swanandx
@swanandx Год назад
Clicked on video blazingly fast
@TON-vz3pe
@TON-vz3pe Год назад
Me too
@PBaraik
@PBaraik Год назад
Same
@ZantierTasa
@ZantierTasa Год назад
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.
@codetothemoon
@codetothemoon Год назад
💯 agree!
@AreQ212
@AreQ212 Год назад
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()) } ```
@SomethingSomething1337
@SomethingSomething1337 Год назад
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 !
@codetothemoon
@codetothemoon Год назад
Great Jaime, I'm really happy you found it valuable! Thanks for watching!
@farzadmf
@farzadmf Год назад
One of the best videos I've seen about these for someone like me that's just learning Rust
@oglothenerd
@oglothenerd 7 месяцев назад
In that use case, you can use .or(SummationError) instead of .map_err(|_| SummationError) method.
@TheWombatGuru
@TheWombatGuru Год назад
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.
@codetothemoon
@codetothemoon Год назад
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!
@theuberlord7402
@theuberlord7402 Год назад
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.
@dimiutube
@dimiutube 9 дней назад
Good explanation about how to elegantly deal with unexpected behaviours! Thanks for that!!
@codetothemoon
@codetothemoon 9 дней назад
thanks, glad you found it valuable!
@thisisscotts
@thisisscotts Год назад
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.
@codetothemoon
@codetothemoon Год назад
Nice thisisscotts! Really happy you found it valuable!
@Yadobler
@Yadobler Год назад
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.
@johnyepthomi892
@johnyepthomi892 Год назад
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.
@MrKeebs
@MrKeebs Год назад
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!
@codetothemoon
@codetothemoon Год назад
Nice, glad you got something useful out of it! Thanks for the kind words!
@LKamii
@LKamii 11 месяцев назад
I needed map_err yesterday and this popped up on suggestions today. Guess I'll fix that unwrap today!
@richardlyon67
@richardlyon67 6 месяцев назад
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!
@bassam.2023
@bassam.2023 2 месяца назад
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! 🙏🏼
@codetothemoon
@codetothemoon 2 месяца назад
love this!! glad it's been valuable!
@MythBusting
@MythBusting Год назад
Loved the video, it was extremely insightful and easy to digest for a beginner like me. I hope you make more of these!
@aussieexpat
@aussieexpat Месяц назад
This really helped me a lot. the functions and containers are so similar it's nice to have a run through these patterns.
@harijayaram
@harijayaram Год назад
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
@Drama-ck2tp
@Drama-ck2tp Год назад
Valuable information! Look forward to your videos always! As I’m currently learning rust
@codetothemoon
@codetothemoon Год назад
Thanks drama, glad you found it valuable!
@avi7278
@avi7278 Год назад
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.
@adammontgomery7980
@adammontgomery7980 Год назад
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.
@yumbuboyumbubo8230
@yumbuboyumbubo8230 Год назад
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!
@codetothemoon
@codetothemoon Год назад
Thanks, glad you found it valuable!
@bibiert45454ifwehgweifhgiwe
@bibiert45454ifwehgweifhgiwe 6 месяцев назад
Thank me so much for helping me through handling errors in Rust. You deepened my knowledge 🙌
@VictorYarema
@VictorYarema Год назад
Insanely good and concise explanation. Thanks. You definitely know how to explain things.
@codetothemoon
@codetothemoon Год назад
Thanks, really happy you found it valuable!
@kavehtehrani
@kavehtehrani 2 месяца назад
That was excellent details on Result and Option. Thank you!
@codetothemoon
@codetothemoon 2 месяца назад
thanks really happy you found it valuable!
@sunitjoshi3573
@sunitjoshi3573 5 месяцев назад
Thanks for putting this out. This was very insightful for newbies like me. 🙏
@chris.davidoff
@chris.davidoff Год назад
This is super helpful, I didn't know about that last one you showed. Thank you!!
@codetothemoon
@codetothemoon Год назад
Glad you found it valuable, thanks for watching Chris!
@silentrandom
@silentrandom Год назад
Really helpful video to understand t OK(), ? and map() functions. Please keep making such videos.
@mystica7284
@mystica7284 Месяц назад
Honestly, i couldn't get my head wrap around on these error handlings before but not anymore . Thank you so much!!!
@Dygear
@Dygear Год назад
I wish I had this video when I was first starting out with Rust. Great video!
@fightndreamr
@fightndreamr Год назад
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.
@cheebadigga4092
@cheebadigga4092 6 месяцев назад
Thanks, the question mark was extremely helpful to replace some of my now redundant match clauses.
@codetothemoon
@codetothemoon 6 месяцев назад
nice, really happy you got something out of it!
@plato4ek
@plato4ek 5 месяцев назад
This is a great video! The example and the explanation done extremely well! I like how you explain hard things.
@IJammyJI
@IJammyJI Год назад
Excellent video! Would love to see more pattern videos like this to add to the toolbox
@codetothemoon
@codetothemoon Год назад
Thanks JammyJ, more are on the way (I'm a poet and I didn't know it)!
@gorudonu
@gorudonu Год назад
Great video! Learnt few new things, please keep making them
@codetothemoon
@codetothemoon Год назад
Thanks gorudonu, more to come!
@jacques-dev
@jacques-dev Год назад
I've definitely been overusing Option when I should be using Result, thanks for your examples.
@codetothemoon
@codetothemoon Год назад
nice, really happy the video helped!
@datag
@datag 5 месяцев назад
Wow, that was a useful video compressed in a few minutes. Thanks!
@codetothemoon
@codetothemoon 5 месяцев назад
thanks, really happy it was helpful!
@ryanlog
@ryanlog 3 месяца назад
BEST VIDEO !!! THIS WAS THE ONLY THING THAT KEPT ME FROM UNDERSTANDIGN RUST !
@codetothemoon
@codetothemoon 2 месяца назад
glad you found it valuable!
@engdoretto
@engdoretto Год назад
Great explanation! Thanks a lot!!!
@dahliaspumpski5837
@dahliaspumpski5837 Год назад
Brilliantly structured, getting me excited to get started with Rust!
@codetothemoon
@codetothemoon Год назад
thank you, very happy it fueled your fire to learn Rust!
@TheRedbeardster
@TheRedbeardster Год назад
Nice explanation for monads from functional languages. Keep up! Thanks!
@codetothemoon
@codetothemoon Год назад
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 🙃
@Gruby7C1h
@Gruby7C1h Год назад
Exactly what I needed, thanks!
@codetothemoon
@codetothemoon Год назад
great, glad you found it valuable!
@starlordcodes
@starlordcodes Год назад
Great Video. I wish there were more people making videos about Rust.
@codetothemoon
@codetothemoon 11 месяцев назад
thanks! and me too.
@robinmoussu
@robinmoussu Год назад
That’s really well explained. I’m sharing it to a friend that want to learn Rust.
@codetothemoon
@codetothemoon Год назад
Thanks Robin, and thanks for sharing it!
@hupa1a
@hupa1a Год назад
Great video. I like how it is structured
@codetothemoon
@codetothemoon Год назад
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
@patricksporl8080
@patricksporl8080 Год назад
Was just reading about that in the rust book two days ago. Great timing!
@codetothemoon
@codetothemoon Год назад
Nice!
@right_jehoon
@right_jehoon Год назад
omg this was so useful! Thank you for good videos :)
Год назад
Really great video about the subject. Thanks a lot!!!
@codetothemoon
@codetothemoon Год назад
thanks glad you got something out of it!
@meartur
@meartur 4 месяца назад
I’m new to Rust. Awesome video, super useful. Thank you!
@codetothemoon
@codetothemoon 4 месяца назад
Great, glad you got something out of it! 😎
@preeeby
@preeeby Год назад
Thanks. This practice examples are great!
@codetothemoon
@codetothemoon Год назад
Thanks preeby, glad you found it valuable!
@NeatMemesDotCom
@NeatMemesDotCom 8 месяцев назад
Each video I watch from this channel makes me less angry with Rust. 🤝
@codetothemoon
@codetothemoon 8 месяцев назад
nice! mission accomplished 😎
@JohnnyVestergaard73
@JohnnyVestergaard73 Год назад
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
@codetothemoon
@codetothemoon Год назад
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.
@edbienes
@edbienes Год назад
Very insightful content! Thank you for this.
@codetothemoon
@codetothemoon Год назад
Thanks for watching Ed!
@oleksandrkovalov1543
@oleksandrkovalov1543 6 месяцев назад
Just brilliant. Thank you so much.
@recarsion
@recarsion Год назад
Hey, there is one thing I'm wondering. Is it good or bad practice to return a polymorphic dyn error type? I had one side project recently where so many different types of errors could occur that I just ended up using Result
@mattlau04
@mattlau04 5 месяцев назад
This is a such a good informative video, i wish i found it sooner!
@miriamramstudio3982
@miriamramstudio3982 Год назад
Great video. Bookmarked it. Will likely go back to it many time in the future ;) Thanks
@codetothemoon
@codetothemoon Год назад
Thanks Miriam, I hope it provides evergreen value for you!
@honeywu6862
@honeywu6862 Год назад
It's so nice !!!! pretty much thanks to your share!!!
@codetothemoon
@codetothemoon Год назад
Thanks for the kind words and thanks for watching!
@patto2k358
@patto2k358 Год назад
this cleared things up thanks
@John223
@John223 Год назад
This was very interesting and very clearly explained. Thank you
@codetothemoon
@codetothemoon Год назад
thanks, glad you found it valuable!
@ErikSchierboom
@ErikSchierboom Год назад
Excellent video! Great tempo.
@codetothemoon
@codetothemoon Год назад
Thanks Eric, glad you found it valuable!
@katopz
@katopz Год назад
The best! I need more of this please! BTW, it would be more handy if you mention thiserror and anyhow in the end. 👍👍👍
@codetothemoon
@codetothemoon Год назад
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
@RustNinja
@RustNinja Год назад
awesome. Thank you man!
@pyrochlore
@pyrochlore Год назад
Very helpful, thanks!
@codetothemoon
@codetothemoon Год назад
thanks, glad you got something out of it!
@mivoe99
@mivoe99 Год назад
Great video! Really good and understandable structure.
@codetothemoon
@codetothemoon Год назад
Thanks mivoe99, glad you found it valuable!
@CaioCodes
@CaioCodes 8 месяцев назад
This video was incredibly well made, it is hard to match. Thank you for the great content.
@codetothemoon
@codetothemoon 8 месяцев назад
thanks so much for the kind words!
@0xSLN
@0xSLN Год назад
That keyboard sound on 2x, music to my ears!
@codetothemoon
@codetothemoon Год назад
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.
@snk-js
@snk-js Год назад
rly rly great I loving all rust lectures form awesome people here in yt
@codetothemoon
@codetothemoon Год назад
Thanks glad you liked it!
@rmiddlehouse
@rmiddlehouse Год назад
These containers are so fundamental to the language.
@codetothemoon
@codetothemoon Год назад
Agree 💯
@mads7401
@mads7401 Год назад
Thanks, great explanation :)
@codetothemoon
@codetothemoon Год назад
thanks for watching, glad you found it valuable!
@ollydix
@ollydix Год назад
Really great tutorials, keep them up!
@codetothemoon
@codetothemoon Год назад
thanks Olly!
@techzoneplus
@techzoneplus Год назад
super helpful, thanks a lot
@codetothemoon
@codetothemoon Год назад
glad you found it valuable, thanks for watching!
@minimaddu
@minimaddu Год назад
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
@codetothemoon
@codetothemoon Год назад
Thanks Madeline, I'll add From into() the video idea list!
@Teflora
@Teflora Год назад
that was great! This is exactly something I struggled with as a Rust beginner but coming from other languages.
@codetothemoon
@codetothemoon Год назад
Thanks Telflora!
@jeanbarbosa9
@jeanbarbosa9 2 месяца назад
Pretty good explanation, I subscribed because of this video.
@catsgotmytongue
@catsgotmytongue Год назад
I've programmed c# for over 15 years, and rust only outside of work. I love your explainations of what's happening in rust.
@codetothemoon
@codetothemoon Год назад
thanks, really happy you're getting something out of the videos!
@Felipe-53
@Felipe-53 Год назад
Maaaan, really throughout. WHat a nice video, wow. I'm impressed. THanks
@codetothemoon
@codetothemoon Год назад
thank you, glad you got something out of it!
@davidraymond8994
@davidraymond8994 Год назад
Awesome thanks great video.
@jambangpisang5809
@jambangpisang5809 Год назад
It would be nice if those 10 patterns got indexed or simply numbered in the video :)
@codetothemoon
@codetothemoon Год назад
Thanks for the feedback, I may add numbers / titles in the future!
@glennmiller394
@glennmiller394 Год назад
Very helpful!
@codetothemoon
@codetothemoon Год назад
Glad you found it valuable Glenn!
@polares8187
@polares8187 Год назад
This was an awesome video. Please do more
@soapbubblesx
@soapbubblesx 8 месяцев назад
Awesome video, thank you
@codetothemoon
@codetothemoon 8 месяцев назад
Glad you liked it!
@zencephalon
@zencephalon Год назад
Great density of information in this video
@codetothemoon
@codetothemoon Год назад
Thanks Matthew!
@fayaz2956
@fayaz2956 Год назад
wow! awesome! thanks
@codetothemoon
@codetothemoon Год назад
Thanks for watching!
@NamasteProgramming
@NamasteProgramming Год назад
Great, didn't know Option and Result share this functionality
@porky1118
@porky1118 Год назад
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.
@DavidGarcia-xz1ui
@DavidGarcia-xz1ui 10 месяцев назад
Thanks!
@jacklong2182
@jacklong2182 Год назад
thanks for this useful tutorial
@codetothemoon
@codetothemoon Год назад
glad you found it valuable, thanks for watching!
@IqweoR
@IqweoR Год назад
Very educational!
@codetothemoon
@codetothemoon Год назад
glad you found it valuable!
@303pix
@303pix 9 месяцев назад
very well explained!
@codetothemoon
@codetothemoon 9 месяцев назад
thank you, glad you got something out of it!
@leighwanstead3254
@leighwanstead3254 Год назад
Very useful instructions
@danny_p466
@danny_p466 Год назад
Great tutorial! Subscribed :)
@CemKavuklu
@CemKavuklu Год назад
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.
@irlshrek
@irlshrek Год назад
id rather he focus on spitting more of these videos out!
@codetothemoon
@codetothemoon Год назад
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 🙃
@CemKavuklu
@CemKavuklu Год назад
@@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 🙂
@Wysumay
@Wysumay Год назад
Incredible content, keep up!
@codetothemoon
@codetothemoon Год назад
thanks so much, glad you found it valuable!
@Felipe-53
@Felipe-53 Год назад
You are awesome. Thanks for the excellent content!
@codetothemoon
@codetothemoon Год назад
thanks for the kind words!
@mariownyou
@mariownyou Год назад
What theme is this, I really need this. I think I'll probably die without this theme :)
@codetothemoon
@codetothemoon Год назад
Sonokai! My current favorite...
@mariownyou
@mariownyou Год назад
@@codetothemoon Thanks, that is awesome. Did you tweak the Colors or what?
@mariownyou
@mariownyou Год назад
Can you share your version please
@ad9633
@ad9633 Год назад
Great video. May I ask what VS code theme you're using?
@artursradionovs9543
@artursradionovs9543 Год назад
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?
@codetothemoon
@codetothemoon Год назад
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.
@frazuppi4897
@frazuppi4897 Год назад
amazing content (as always)
@michawhite7613
@michawhite7613 Год назад
You can remove the call to map_err at the end by implementing From for SummationError
@Ruhrpottpatriot
@Ruhrpottpatriot Год назад
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.
Далее
Ace Rust Macros ♠️ the declarative kind
14:06
Просмотров 38 тыс.
You Should Really Know These Traits in Rust
18:36
Просмотров 11 тыс.
Conquering fears and slippery slops on two wheels!
00:18
你们会选择哪一辆呢#short #angel #clown
00:20
Rust Powered Polymorphism ⚡️ With Traits
9:55
Просмотров 92 тыс.
Arc instead of Vec? | Prime Reacts
37:18
Просмотров 62 тыс.
but what is 'a lifetime?
12:20
Просмотров 61 тыс.
Writing My Own Database From Scratch
42:00
Просмотров 154 тыс.
8 Design Patterns | Prime Reacts
22:10
Просмотров 390 тыс.
8 deadly mistakes beginner Rust developers make
14:14
Просмотров 158 тыс.
The Uiua Programming Language Caught Me By Surprise
12:24
Rust Demystified 🪄 Simplifying The Toughest Parts
14:05
Rust Functions Are Weird (But Be Glad)
19:52
Просмотров 129 тыс.
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Просмотров 37 тыс.
Blackview N6000SE Краш Тест!
1:00
Просмотров 34 тыс.