Rust's Most Important Containers 📦 10 Useful Patterns

  Рет қаралды 114,010

Code to the Moon

Code to the Moon

Жыл бұрын

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

Пікірлер: 343
@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
@theaiguy_
@theaiguy_ 7 ай бұрын
Yeah... 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()) } ```
@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.
@farzadmf
@farzadmf Жыл бұрын
One of the best videos I've seen about these for someone like me that's just learning Rust
@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.
@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!
@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!
@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.
@richardlyon67
@richardlyon67 5 ай бұрын
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!
@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
@aussieexpat
@aussieexpat 25 күн бұрын
This really helped me a lot. the functions and containers are so similar it's nice to have a run through these patterns.
@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!
@engdoretto
@engdoretto Жыл бұрын
Great explanation! Thanks a lot!!!
@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.
@bibiert45454ifwehgweifhgiwe
@bibiert45454ifwehgweifhgiwe 6 ай бұрын
Thank me so much for helping me through handling errors in Rust. You deepened my knowledge 🙌
@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.
@oleksandrkovalov1543
@oleksandrkovalov1543 6 ай бұрын
Just brilliant. Thank you so much.
@Dygear
@Dygear Жыл бұрын
I wish I had this video when I was first starting out with Rust. Great video!
@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!
@patto2k358
@patto2k358 Жыл бұрын
this cleared things up thanks
@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!
@mystica7284
@mystica7284 28 күн бұрын
Honestly, i couldn't get my head wrap around on these error handlings before but not anymore . Thank you so much!!!
@silentrandom
@silentrandom Жыл бұрын
Really helpful video to understand t OK(), ? and map() functions. Please keep making such videos.
@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!
@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!
@RustNinja
@RustNinja Жыл бұрын
awesome. Thank you man!
@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.
Жыл бұрын
Really great video about the subject. Thanks a lot!!!
@codetothemoon
@codetothemoon Жыл бұрын
thanks glad you got something out of it!
@plato4ek
@plato4ek 4 ай бұрын
This is a great video! The example and the explanation done extremely well! I like how you explain hard things.
@VictorYarema
@VictorYarema Жыл бұрын
Insanely good and concise explanation. Thanks. You definitely know how to explain things.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, really happy you found it valuable!
@cheebadigga4092
@cheebadigga4092 5 ай бұрын
Thanks, the question mark was extremely helpful to replace some of my now redundant match clauses.
@codetothemoon
@codetothemoon 5 ай бұрын
nice, really happy you got something out of it!
@gorudonu
@gorudonu Жыл бұрын
Great video! Learnt few new things, please keep making them
@codetothemoon
@codetothemoon Жыл бұрын
Thanks gorudonu, more to come!
@right_jehoon
@right_jehoon Жыл бұрын
omg this was so useful! Thank you for good videos :)
@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!
@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!
@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)!
@kavehtehrani
@kavehtehrani Ай бұрын
That was excellent details on Result and Option. Thank you!
@codetothemoon
@codetothemoon Ай бұрын
thanks really happy you found it valuable!
@Gruby7C1h
@Gruby7C1h Жыл бұрын
Exactly what I needed, thanks!
@codetothemoon
@codetothemoon Жыл бұрын
great, glad you found it valuable!
@preeeby
@preeeby Жыл бұрын
Thanks. This practice examples are great!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks preeby, glad you found it valuable!
@davidraymond8994
@davidraymond8994 Жыл бұрын
Awesome thanks great video.
@ricardom860
@ricardom860 Ай бұрын
excelent video thanks you!!
@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!
@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
@pyrochlore
@pyrochlore Жыл бұрын
Very helpful, thanks!
@codetothemoon
@codetothemoon Жыл бұрын
thanks, glad you got something out of it!
@edbienes
@edbienes Жыл бұрын
Very insightful content! Thank you for this.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Ed!
@mattlau04
@mattlau04 5 ай бұрын
This is a such a good informative video, i wish i found it sooner!
@honeywu6862
@honeywu6862 Жыл бұрын
It's so nice !!!! pretty much thanks to your share!!!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for the kind words and thanks for watching!
@datag
@datag 4 ай бұрын
Wow, that was a useful video compressed in a few minutes. Thanks!
@codetothemoon
@codetothemoon 4 ай бұрын
thanks, really happy it was helpful!
@meartur
@meartur 3 ай бұрын
I’m new to Rust. Awesome video, super useful. Thank you!
@codetothemoon
@codetothemoon 3 ай бұрын
Great, glad you got something out of it! 😎
@starlordcodes
@starlordcodes 11 ай бұрын
Great Video. I wish there were more people making videos about Rust.
@codetothemoon
@codetothemoon 11 ай бұрын
thanks! and me too.
@patricksporl8080
@patricksporl8080 Жыл бұрын
Was just reading about that in the rust book two days ago. Great timing!
@codetothemoon
@codetothemoon Жыл бұрын
Nice!
@ryanlog
@ryanlog 2 ай бұрын
BEST VIDEO !!! THIS WAS THE ONLY THING THAT KEPT ME FROM UNDERSTANDIGN RUST !
@codetothemoon
@codetothemoon 2 ай бұрын
glad you found it valuable!
@leighwanstead3254
@leighwanstead3254 Жыл бұрын
Very useful instructions
@techzoneplus
@techzoneplus Жыл бұрын
super helpful, thanks a lot
@codetothemoon
@codetothemoon Жыл бұрын
glad you found it valuable, thanks for watching!
@mads7401
@mads7401 Жыл бұрын
Thanks, great explanation :)
@codetothemoon
@codetothemoon Жыл бұрын
thanks for watching, glad you found it valuable!
@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!
@DavidGarcia-xz1ui
@DavidGarcia-xz1ui 9 ай бұрын
Thanks!
@mivoe99
@mivoe99 Жыл бұрын
Great video! Really good and understandable structure.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks mivoe99, glad you found it valuable!
@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 🙃
@ErikSchierboom
@ErikSchierboom Жыл бұрын
Excellent video! Great tempo.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Eric, glad you found it valuable!
@jeanbarbosa9
@jeanbarbosa9 Ай бұрын
Pretty good explanation, I subscribed because of this video.
@glennmiller394
@glennmiller394 Жыл бұрын
Very helpful!
@codetothemoon
@codetothemoon Жыл бұрын
Glad you found it valuable Glenn!
@John223
@John223 Жыл бұрын
This was very interesting and very clearly explained. Thank you
@codetothemoon
@codetothemoon Жыл бұрын
thanks, glad you found it valuable!
@danny_p466
@danny_p466 Жыл бұрын
Great tutorial! Subscribed :)
@fayaz2956
@fayaz2956 Жыл бұрын
wow! awesome! thanks
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching!
@polares8187
@polares8187 Жыл бұрын
This was an awesome video. Please do more
@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!
@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!
@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!
@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!
@ollydix
@ollydix Жыл бұрын
Really great tutorials, keep them up!
@codetothemoon
@codetothemoon Жыл бұрын
thanks Olly!
@303pix
@303pix 9 ай бұрын
very well explained!
@codetothemoon
@codetothemoon 9 ай бұрын
thank you, glad you got something out of it!
@user-jg1vz1zo8o
@user-jg1vz1zo8o Жыл бұрын
super helpful
@codetothemoon
@codetothemoon Жыл бұрын
glad you found it valuable!
@zencephalon
@zencephalon Жыл бұрын
Great density of information in this video
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Matthew!
@cmthimmaiah
@cmthimmaiah Жыл бұрын
Fantastic !!!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Mohith!
@frazuppi4897
@frazuppi4897 Жыл бұрын
amazing content (as always)
@Felipe-53
@Felipe-53 Жыл бұрын
You are awesome. Thanks for the excellent content!
@codetothemoon
@codetothemoon Жыл бұрын
thanks for the kind words!
@CaioCodes
@CaioCodes 7 ай бұрын
This video was incredibly well made, it is hard to match. Thank you for the great content.
@codetothemoon
@codetothemoon 7 ай бұрын
thanks so much for the kind words!
@Wysumay
@Wysumay Жыл бұрын
Incredible content, keep up!
@codetothemoon
@codetothemoon Жыл бұрын
thanks so much, glad you found it valuable!
@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!
@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
@NamasteProgramming
@NamasteProgramming Жыл бұрын
Great, didn't know Option and Result share this functionality
@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!
@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.
@DiaaKasem0
@DiaaKasem0 Жыл бұрын
Thank You
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching!
@marcin9957
@marcin9957 3 ай бұрын
Great video :D
@joeldpalmer
@joeldpalmer Жыл бұрын
Well done 👍
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Joel!
@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!
@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
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars 7 ай бұрын
wow, thank you and subbed :)
@codetothemoon
@codetothemoon 7 ай бұрын
thank you, very happy to have you onboard!
@NeatMemesDotCom
@NeatMemesDotCom 8 ай бұрын
Each video I watch from this channel makes me less angry with Rust. 🤝
@codetothemoon
@codetothemoon 8 ай бұрын
nice! mission accomplished 😎
@vadimemelin2941
@vadimemelin2941 5 ай бұрын
Man, you've addressed my inner angry funcy npc at 2:28 🤣
@alextran72
@alextran72 Жыл бұрын
This is a gold video
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Alex!
@DJenriqez
@DJenriqez Жыл бұрын
nice video, as always :)
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Erik!
@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.
Ace Rust Macros ♠️ the declarative kind
14:06
Code to the Moon
Рет қаралды 37 М.
Idiomatic Rust - Builder Pattern
8:13
Let's Get Rusty
Рет қаралды 26 М.
100❤️
00:20
Nonomen ノノメン
Рет қаралды 73 МЛН
⬅️🤔➡️
00:31
Celine Dept
Рет қаралды 36 МЛН
When someone reclines their seat ✈️
00:21
Adam W
Рет қаралды 29 МЛН
Rust Powered Polymorphism ⚡️ With Traits
9:55
Code to the Moon
Рет қаралды 90 М.
Rust Data Modelling Without Classes
11:25
No Boilerplate
Рет қаралды 161 М.
Rust Interior Mutability - Sneaking By The Borrow Checker
16:02
Code to the Moon
Рет қаралды 64 М.
Rust Programming: TypeState Builder Pattern Explained
14:30
Jeremy Chone
Рет қаралды 28 М.
Arc instead of Vec? | Prime Reacts
37:18
ThePrimeTime
Рет қаралды 61 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 135 М.
The Dygma Defy: A Software Developer's Dream?
8:16
Code to the Moon
Рет қаралды 56 М.
The Uiua Programming Language Caught Me By Surprise
12:24
Code to the Moon
Рет қаралды 49 М.
Java constructors 👷
10:37
Bro Code
Рет қаралды 165 М.
APPLE совершила РЕВОЛЮЦИЮ!
0:39
ÉЖИ АКСЁНОВ
Рет қаралды 1,6 МЛН
Девушка и AirPods Max 😳
0:59
ОТЛИЧНИКИ
Рет қаралды 17 М.
Cadiz smart lock official account unlocks the aesthetics of returning home
0:30
сюрприз
1:00
Capex0
Рет қаралды 1,4 МЛН
Секретный смартфон Apple без камеры для работы на АЭС
0:22
#miniphone
0:16
Miniphone
Рет қаралды 3,1 МЛН