Rust Demystified 🪄 Simplifying The Toughest Parts

  Рет қаралды 171,185

Code to the Moon

Code to the Moon

Күн бұрын

Rust can be frustrating to learn even for developers with years of experience in a language such as Java, JavaScript, or C++. But most of the friction in learning Rust comes from a few core concepts that don't really exist in any other language. These concepts are what gives Rust an edge over other languages. Once they are understood, the Rust journey becomes a lot easier. Moreover, these concepts aren't hard to understand when they are presented using the simplest example possible.
00:00 Introduction
01:41 Ownership and Why
02:46 3 Alternatives To Ownership Changes
05:36 Mutable References
07:45 Lifetimes
11:54 Struct Lifetimes
13:30 Conclusion
---
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!!!
Building A Second Brain book: amzn.to/3cIShWf
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

Пікірлер: 558
@codetothemoon
@codetothemoon Жыл бұрын
ERRATA * I mention that you get a segfault when you don't deallocate memory in C/C++ - I meant to say that you get a segfault when you try to reference memory that was already deallocated. Not deallocating memory will lead to memory leaks in some cases.
@raiyanahmed3534
@raiyanahmed3534 Жыл бұрын
nah still,, a banger video
@codetothemoon
@codetothemoon Жыл бұрын
@@raiyanahmed3534 thanks!
@AGBuzz182
@AGBuzz182 Жыл бұрын
It's not generally true that accessing deallocated memory causes a segfault either. Actually, it would be more helpful if that was the case, since it would be easier to debug than the case where your program is silently accessing data that may or may not be garbage depending on the execution state.
@MikaelMurstam
@MikaelMurstam Жыл бұрын
dammit I was gonna yell at you :)
@patricklittle1002
@patricklittle1002 Жыл бұрын
Many embedded systems just use static allocation, so you never deallocate by design.
@abraham7966
@abraham7966 Жыл бұрын
I like what you are doing here. I am glad that No Boilerplate is influencing people because I am sick of all the stupid presentations in other channels. 1 minute of BS, songs, animations, and people presenting their channels and welcoming as if we were 6 years old watching Ryan's toys reviews.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks! re: the filler stuff - yeah I'm not a fan of lengthy introductions either. I'm not entirely above obnoxious animations (see earlier videos) but I definitely like to get to the point 😎
@cathalogrady2331
@cathalogrady2331 Жыл бұрын
you dont get a segfault if you dont deallocate memory. Segfaults are when the kernel informs your process that you accesed memory you shouldnt have
@codetothemoon
@codetothemoon Жыл бұрын
ugh, you're absolutely right! This was an egregious mistake. Not deallocating will result in a memory leak. I meant to refer to the case where we erroneously deallocate memory and then try to reference that memory. I'll put a note in the description, thanks for pointing this out!
@GottZ
@GottZ Жыл бұрын
yo ucan also segfault by accessing memory you never had access to. (in most cases..)
@cathalogrady2331
@cathalogrady2331 Жыл бұрын
@@GottZ yes I never said that wasnt the caes, I said purely deallocation alone doesnt provoke a segfault directly
@pinealservo
@pinealservo Жыл бұрын
@@codetothemoon Also, you can segfault if you correctly deallocate memory and then (because you had more than one reference) you deallocate it again and corrupt the malloc recordkeeping. Sometimes this takes quite a while to blow up on you!
@hotpawsmathsandscience3124
@hotpawsmathsandscience3124 Жыл бұрын
you segfault every time you run your c program for the first time
@lukakralik2346
@lukakralik2346 Жыл бұрын
I was learning Rust for some time now. I already understood borrowing and the entire ownership model really well but didn't admit I don't get lifetimes at all. Today it finally cliked for me (after 3 months of learning rust :D). It was so obvious and under my nose the entire time! Thank you very much for your amazing explanation! I am incredibly excited to finally dive into Rust completely.
@codetothemoon
@codetothemoon Жыл бұрын
Nice, glad you found the lifetime explanation helpful! I wasn't 100% sure if my explanation was as straightforward as possible, so this anecdote makes me very happy.
@megumin4625
@megumin4625 Жыл бұрын
7:44 In case anyone is wondering why the mutable reference will work if you remove the last `print_some_struct` which uses an immutable reference. This is because of NLL (non-lexical lifetimes). In short, the compiler infers that it is able to drop the immutable reference borrow before it gets to the mutable reference, because it's not used anywhere later. Thus, you only have one mutable reference, which doesn't break any rules
@robonator2945
@robonator2945 8 ай бұрын
Great, as if Rust hadn't gone out of it's way to make things confusing already they don't have NULL, they have NLL. I'm half convinced this is intentional at this point and this is all just some cruel trick by some trickster diety of programming to make an incredible language that is intentionally designed to drive as many people as possible away from using it. Wait... trickster diety, Loki - Odin lang, Odin... checkmate athiests.
@z4nshin
@z4nshin Ай бұрын
It's good you mentioned this. This confused me for a long time.
@mdshohidurrahman1121
@mdshohidurrahman1121 Жыл бұрын
Every new rust developer should watch this video,very effective as always.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks! I really do hope this can be a resource for newcomers that removes as much of the friction as possible.
@emiliorojas583
@emiliorojas583 Жыл бұрын
@@codetothemoon it really does XD. I'm eager to learn rust and this video made me more interested. this video is pure gold. from the bottom of my heart: thanks you
@brunkel8269
@brunkel8269 Жыл бұрын
Your videos on Rust are well explained and to the point. Plus with the production quality of these video's, it will only take a matter of time before your channel blows up!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for the kind words Brunkel! I aim to make videos that are engaging but still pack in as much value as possible. I'd love to do this as a full time job, I appreciate you watching as it really helps me toward that goal!
@andythedishwasher1117
@andythedishwasher1117 Жыл бұрын
I just started learning Rust a couple weeks ago and decided to build a calculator in a Yew app. Finally got it up and running last night. I was excited about the ownership concept for similar reasons to what you described due to enormous frustration with trying to rebuild Javascript after encountering runtime errors on runtimes I couldn't test in the development phase. Turns out, it made the calculator thing easier rather than harder by some miracle. I did run into some pretty confusing lifetime errors though. You have to be super careful where you declare things and how long you keep them around, but if you can do that, you're pretty much gold. The whole process for building and deploying a Yew app was a fair bit more enjoyable than React as well. Definitely nicer than wrestling with node_modules.
@codetothemoon
@codetothemoon Жыл бұрын
Nice Andy! I love hearing stories like this. I imagine others will have similar experiences
@soumen_pradhan
@soumen_pradhan Жыл бұрын
Would like to see one on Procedural Macros as well. They are essentially magic to me right now.
@codetothemoon
@codetothemoon Жыл бұрын
Great idea Soumen! In fact I have this in the works already, it might be the next video.
@marl3x
@marl3x Жыл бұрын
Macros are the reason I immediately stopped using Rust after learning it through their book. I knew how to code in Rust, wanted to build something and suddenly nothing made sense anymore because everything was obfuscated by these stupid magic Macros. But apparently that's just something you have to deal with, some libraries just don't want you to know what's really happening.
@erikfundercarstensen7344
@erikfundercarstensen7344 Жыл бұрын
@@marl3x I think its ‘cargo expand’ which can be used for printing the result of macro expansion in a given program. I think the library developers are prioritizing usability and small code size over understandability, which sadly sometimes are tradeoffs
@SaHaRaSquad
@SaHaRaSquad Жыл бұрын
​@@marl3x I don't think I've ever used any third-party macros, only the ones from stdlib and my own. As Rust docs for libraries are auto-generated from code they contain everything either way, so you can usually avoid macros. I know some libraries separate their macros into another optional package as well.
@porky1118
@porky1118 Жыл бұрын
@@marl3x I'm using Rust for years already and I almost never come across libraries, which use macros. I also don't use a lot of macros myself. Almost always, it's been macro specific libraries. Mostly custom derives. If one uses macros, it's not about not wanting the user to know, what's happening internally, it's a simplified syntax for a special purpose. But I also don't like, when I see a library, which forces me to use a lot of weird macros.
@dazealex
@dazealex Жыл бұрын
I've watched many channels, but yours is by far the best explanation style I've seen so far! Kudos bro.
@AndreCarneiro666
@AndreCarneiro666 Жыл бұрын
So much effort to return a variable!
@codetothemoon
@codetothemoon Жыл бұрын
hah! luckily it's a bit of a corner case...
@thisoldproperty
@thisoldproperty Жыл бұрын
This was my second rust video I’ve watched and as a senior coder even I’m amazed at the level of thought that has gone into the language.
@codetothemoon
@codetothemoon Жыл бұрын
I agree! As with any language, there are some aspects I don't like but it's really incredible what the language has accomplished!
@user-vs9uf3ny8z
@user-vs9uf3ny8z Жыл бұрын
I definitely got tripped up when first encountering the syntax and explanations around this in official docs and other resources. You really broke things down in a beautifully comprehensible way. Thanks so much for the vid!
@codetothemoon
@codetothemoon Жыл бұрын
thanks, really happy you liked it!
@voidemperor9372
@voidemperor9372 Жыл бұрын
Magicccc!! we need more of these short videos. Great job :)
@codetothemoon
@codetothemoon Жыл бұрын
Thanks void, more to come!
@Gemasted
@Gemasted Жыл бұрын
Good stuff :), though your explanation of copy was a bit lacking, it's not just that it's implicit it's also that it requires the memory copy-able one to one, this works great when you have a struct full of primitives since copying the memory is fast, however if your struct contained pointers to heap memory such as box or vec then you wouldn't be able to implement copy since just copying the memory would create a cloned object with the same references. Furthermore copying the struct especially when it only has 1 primitive field is a zero cost abstraction and so it would be no different than giving the print struct a reference.
@codetothemoon
@codetothemoon Жыл бұрын
Jannick - you're so right! Thanks for pointing this out. I'm going to start an errata post and mention this and the incorrect statement I made about segfaults in C++...
@notengonickname
@notengonickname Жыл бұрын
I started learning Rust a couple weeks ago and had a hard time grasping the concept of Lifetimes... which now I do because of your video! Great content 👌Thanks a lot !!!
@codetothemoon
@codetothemoon Жыл бұрын
Nice Jorge! Glad you found the video helpful!
@ItsGazareth
@ItsGazareth Жыл бұрын
This was great, I love how you gave actual examples for the things the compiler was complaining about.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Gazareth, glad you found it valuable!
@richsadowsky8580
@richsadowsky8580 Жыл бұрын
Another great video. Lifetimes have been giving me grief and this helped. With 40 years experience programming in at least a dozen languages, these really are the somewhat unique and challenging bits of Rust.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Rich, really happy you found it helpful!
@TheRealAfroRick
@TheRealAfroRick 8 ай бұрын
Nice. Really love how clearly you explained the concepts - especially the WHY as that makes it easier to peer behind the compiler and understand what's happening - ESPECIALLY with Lifetimes. I'll have to watch a few more times for it to burn into long term memory, but this is the first time I've understood lifetimes 😂
@codetothemoon
@codetothemoon 8 ай бұрын
thank you, really happy you got something out of it! i felt like so many people get stuck on these concepts, and there was an easier way of approaching them...
@gladoseus
@gladoseus 4 ай бұрын
Very clear explanations and straight to the point. This the best 14 minutes of my rust journey so far.
@codetothemoon
@codetothemoon 4 ай бұрын
thank you, glad you got something out of it!
@tobias3581
@tobias3581 Жыл бұрын
Amazing just got fed up with JS for the eleventh time this week and started reading rust docs and now this, thanks!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Tobias, I really appreciate you watching each video!
@sergiuoanes4635
@sergiuoanes4635 Жыл бұрын
this really helped me a lot understanding these concepts. ...huge THANK YOU!!!
@codetothemoon
@codetothemoon Жыл бұрын
glad you found it valuable, thanks for watching!
@TheArgentan
@TheArgentan Жыл бұрын
Great video! I really feel like I've understood borrowing and lifetimes for the first time since the first time I was rust-curious a year ago
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Pat, really happy this helped clear up the confusion around these concepts!
@ItzKernel
@ItzKernel Жыл бұрын
this was a very helpful video. i already knew how to use lifetimes because i got used to them, but i couldn't have explained how they work. now everything is crystal clear. keep up the good work!
@codetothemoon
@codetothemoon Жыл бұрын
glad it was helpful, and thank you!
@torppe2226
@torppe2226 Жыл бұрын
Incredibly easy to understand and straight to the point video, keep up the good work!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, glad you found it valuable!
@LukasRotermund
@LukasRotermund Ай бұрын
Wow, this is a brilliant video! I had some trouble with the borrowing, but now I've got it, thanks to you! 💡
@codetothemoon
@codetothemoon Ай бұрын
fantastic, really happy this particular approach made things clearer for you!
@QazCetelic
@QazCetelic Жыл бұрын
These were indeed exactly the parts that were hard to get used to as someone who is used to GC collected languages. Very useful tutorial.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Qaz, glad you found it valuable!
@mrhoxell
@mrhoxell 3 ай бұрын
Very good tutorial. I had trouble with moving playing with Rust and despite understanding somehow how it's working, this explains the basic concepts very well. Thanks a lot
@codetothemoon
@codetothemoon 3 ай бұрын
nice, really happy it was helpful!
@israrkarimzai
@israrkarimzai Жыл бұрын
Thank you. Amazingly explained.
@eladmatia9953
@eladmatia9953 Жыл бұрын
I think I finally understand lifetimes. Simple and elegant. Thank you!
@codetothemoon
@codetothemoon Жыл бұрын
Nice, glad you found the video helpful, thanks for watching!
@mastamitche
@mastamitche 8 күн бұрын
This was very clear and useful. Best tutorial for rust I've found
@DashLiu
@DashLiu 19 сағат бұрын
got the concepts,thank you very much!
@user-cl5wn9fz7f
@user-cl5wn9fz7f Жыл бұрын
This channel is a blessing
@codetothemoon
@codetothemoon Жыл бұрын
Very happy to have you onboard!
@introspecticon
@introspecticon Жыл бұрын
Great pacing and presentation - quickly becoming one of my favorite Rust channels
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for the kind words! If there are any topics you'd like to see let me know!
@introspecticon
@introspecticon Жыл бұрын
@@codetothemoon these might be a bit niche, but here are a few things I'd like to learn more about in no particular order: - speeding up python code using PyO3 - high-performance/multithreaded data processing with ndarray and polars - speeding up a React/Svelte SPA by writing expensive business logic in Rust and compiling it to WASM - The current status of WASM/WASI and when to expect WASM to get better at DOM manipulation
@Kiwifruit00
@Kiwifruit00 Жыл бұрын
Thank you for this! I really love your content and would like to see more.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching, more is on the way!
@flippert0
@flippert0 6 ай бұрын
Thanks for demystifying the lifetime concept. What I didn't get up to this video, was that you introduce the lifetime *in the function* as some form of a guarantee about the variables not going out of scope, but it is the *caller* of the function to make sure this guarantee is upheld .
@mbrav
@mbrav Жыл бұрын
I have finished the Rust book along with rustlings exercises, which I cannot recommend enough to everyone who wants to learn Rust. But this video was so great at solidifying the concepts I learned! Please do more content like this! *subscribed*
@codetothemoon
@codetothemoon Жыл бұрын
The Rust Book is fantastic! More videos on the way. Very Happy to have you onboard!
@egorandreevich7830
@egorandreevich7830 Жыл бұрын
What's wrong with rustlings? I wanted to try it.
@mbrav
@mbrav Жыл бұрын
@@egorandreevich7830 Nothing, rustlings exercises are wonderful
@egorandreevich7830
@egorandreevich7830 Жыл бұрын
​@@mbrav so why you cannot recommend it?
@mbrav
@mbrav Жыл бұрын
@@egorandreevich7830 I cannot recommend it ENOUGH. Meaning is inversed.
@maxreuv
@maxreuv Жыл бұрын
Very well delivered and easy to follow! Thank you!
@codetothemoon
@codetothemoon Жыл бұрын
thanks maxreuv, glad you found it valuable!
@tuanlam999
@tuanlam999 Жыл бұрын
Very clear explanation. Thank you.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Tuan!
@achimwasp
@achimwasp Жыл бұрын
Shows why I like languages with GC so much. (defn bigger [a b] (if (> a b) a b)) (bigger 3 5) Done. Depends of course on which you prefer or need for the use case: developer performance or code/app performance.
@mateusoliveira2776
@mateusoliveira2776 Жыл бұрын
I would love a bigger video on this with a focus on examples! Great vid
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, bigger examples are on the way!
@bornfree465
@bornfree465 Жыл бұрын
Just the video i was looking for ...awesome!
@codetothemoon
@codetothemoon Жыл бұрын
thanks, glad you got something out of it!
@ToukiMS
@ToukiMS Жыл бұрын
Thank you for such clear explanations !
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, happy you found it valuable!
@lew_wloczega
@lew_wloczega Жыл бұрын
Very helpful video. Thanks alot.
@luiscarloscorderopena7030
@luiscarloscorderopena7030 Жыл бұрын
Excelent explanation!, really loved it! it's very concise and to the point
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Luis, glad you found it valuable!
@1Dr490n
@1Dr490n Жыл бұрын
I learned this ownership & borrowing system (as well as most of the things I know about rust (not a lot)) by making a Compiler for a language that also uses that so I wrote some simple Rust code, compiled it to LLVM IR and tried to understand it. Best learning technique👍
@_dinesh
@_dinesh Жыл бұрын
Excellent explanation!!! keep doing more videos like this!!
@codetothemoon
@codetothemoon Жыл бұрын
thanks, more to come!
@sharperguy
@sharperguy Жыл бұрын
The thing about Rust is it is an incredibly deep and powerful language. And for good reason. But that means that it will take longer to learn than many of the most popular languages out there today. So the productivity curve for a new developer will start off relatively slow, but as they gain experience eventually they will end up being able to build things much more quickly and much higher quality than in other languages.
@codetothemoon
@codetothemoon Жыл бұрын
agree! 💯
@keludgraphica80
@keludgraphica80 9 ай бұрын
that's pretty much the same with other languages, like C++ for instances. You start slow that when you gain understanding and experiences your productivity will rose
@phutchins3
@phutchins3 Жыл бұрын
Very well explained, thank you!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching, glad you found it valuable!
@AbhishekBajpaiHere
@AbhishekBajpaiHere Жыл бұрын
Loved it, thanks for the explanation
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Abishek!
@JanVotava
@JanVotava Жыл бұрын
Great video. You just made me to try clean my laptop screen with that grey line on your camera background 😅.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks and hah! Green screen keying is tricky to get exactly right sometimes.... 🙃
@jrtomsic
@jrtomsic 10 ай бұрын
Thanks for this video. I tried rust for a while and basically just fumbled with references and lifetime definitions until it did what I want. This video does a good job showing what each of those concepts is so I can be deliberate about my code next time.
@codetothemoon
@codetothemoon 10 ай бұрын
nice, really happy you got something out of the video! 😎
@Omegka
@Omegka Жыл бұрын
Great video. Really clear explanation.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks, very happy you found it valuable!
@user-sd4zb7ek1l
@user-sd4zb7ek1l 2 ай бұрын
Thanks for all your explanatory videos on Rust. I am learning just as much I should from videos without the becoming tutorial dull. I had one question, which I later checked on my own, shouldn't you have removed Clone and Copy Derives after there work was done, it would have removed unnecessary confusions. Keep making these learnable videos without making them into dull tutorial. Thank you again. ❤
@qwertgfhxc
@qwertgfhxc 7 ай бұрын
This was incredibly useful, thanks a lot!
@codetothemoon
@codetothemoon 7 ай бұрын
nice, really happy you found it valuable!
@ziiirozone
@ziiirozone Жыл бұрын
Very good video for beginners, i would have liked to see it myself a bit before, when i was struggling to understand and use borrowing and references, but it did make me understand lifetimes well, very good job !
@codetothemoon
@codetothemoon Жыл бұрын
thanks ziii, glad you found it valuable!
@jambangpisang5809
@jambangpisang5809 Жыл бұрын
Thank you for the indexed video!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Jambang!
@carrotstickz7290
@carrotstickz7290 Жыл бұрын
thanks for the clear and concise video!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Carrot! It'd be fair to attribute at least some of that clarity to your abundant levels of vitamin A!
@NovaAquarius
@NovaAquarius Жыл бұрын
Crystal clear explanation. I tried to learn rust a while but everytime I came across borrowing errors I got frustrated and ended up not persuing rust. Maybe after this video I will try again
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Nova, glad you found it valuable!
@hamdysaadpersonal
@hamdysaadpersonal Жыл бұрын
Really it's a great video , keep going and we wand bigger projects 💙🔥
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Hamdy! Bigger projects are on the way!
@rtdietrich
@rtdietrich 4 ай бұрын
I've finally understood it! THANKS
@codetothemoon
@codetothemoon 4 ай бұрын
nice! really happy you got something out of it!
@user-fk5fw3cu4m
@user-fk5fw3cu4m Жыл бұрын
Thank you for your videos! Really want to watch video about traits and derive from you.
@codetothemoon
@codetothemoon Жыл бұрын
Glad you found them valuable! I'll put traits and derive on the video ideas list!
@apaksimen
@apaksimen Жыл бұрын
perfect explanation, thank you!
@codetothemoon
@codetothemoon Жыл бұрын
thanks, glad you found it valuable!
@jacoballen6099
@jacoballen6099 Жыл бұрын
Killer video. Bet this guys channel blows up if he keeps making content in this style
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Jacob, I hope you're right!
@ArnabGuides
@ArnabGuides Жыл бұрын
this is explanation to the moon. Keep the tutorials coming. Thanks :)
@codetothemoon
@codetothemoon Жыл бұрын
glad you found it valuable, more are on the way!
@abhinandshibu4430
@abhinandshibu4430 Жыл бұрын
Thank you this helped a lot!
@codetothemoon
@codetothemoon Жыл бұрын
Nice, glad you found it valuable Abhinand!
@Kodlak15
@Kodlak15 Жыл бұрын
This is very helpful. Thank you!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Cody, glad you found it valuable!
@upriser77
@upriser77 Жыл бұрын
Thank you so much! I've finally understood the lifetime.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Chan, glad you found it valuable!
@dev_jeongdaeri
@dev_jeongdaeri Жыл бұрын
You are amazing! Thanks for the great content! 😊
@codetothemoon
@codetothemoon Жыл бұрын
Thank you so much for watching!
@felixgiffuni9154
@felixgiffuni9154 2 ай бұрын
Thanks. Very helpful.
@neilclay5835
@neilclay5835 Жыл бұрын
Great little vid, thanks.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching Neil!
@laxmiprasadoli5989
@laxmiprasadoli5989 8 ай бұрын
Great explanation. Thanks :)
@codetothemoon
@codetothemoon 8 ай бұрын
thanks for the kind words, glad you got something out of it!
@KnightMirkoYo
@KnightMirkoYo Жыл бұрын
The borrow checker makes so much sense, it's surprising that it never got popular before rust. Rust makes me think about memory and types, and the compiler ensures I mostly make correct choices. It feels awesome.
@codetothemoon
@codetothemoon Жыл бұрын
I agree! it's interesting how many recent innovations in software (like the borrow checker) are completely independent of modern hardware and theoretically could have been discovered decades ago. Blockchain and Transformers are also great examples.
@raaman852
@raaman852 8 ай бұрын
Thanks for amazing explanation.
@codetothemoon
@codetothemoon 8 ай бұрын
very happy you got something out of it!
@elanticrypt0
@elanticrypt0 Жыл бұрын
simply and useful. thank you
@codetothemoon
@codetothemoon Жыл бұрын
nice, glad you got something out of it!
@awunnenb
@awunnenb 4 ай бұрын
Thank you very much that helped me a lot
@HansBaier
@HansBaier Жыл бұрын
excellent explanation, one of the best so far 👍🏻👍🏻👍🏻
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Hans, glad you found it valuable!
@correabuscar
@correabuscar Жыл бұрын
great info, cheers
@AssemblyWizard
@AssemblyWizard Жыл бұрын
Great video, I think you should have also explained here about non-lexical lifetimes (at 9:20 you used `bigger` on line 25 to prevent its NLL, but this can confuse many beginners as to why some scenarios don't give an error when you said they should), and also slices (I was very confused about them as a beginner)
@codetothemoon
@codetothemoon Жыл бұрын
Great points - I'd love to go into lifetimes in more detail in a future video. Slices too!
@TheBrazilRules
@TheBrazilRules Жыл бұрын
This is so easy for people who worked with pointers before. Really says a lot about the state of programming nowadays
@codetothemoon
@codetothemoon Жыл бұрын
glad to hear that it's easy for some - I personally found it a bit challenging to grasp at first despite having substantial C++ experience
@TheBrazilRules
@TheBrazilRules Жыл бұрын
@@codetothemoon Maybe because you don't had anyone to explain it to you through examples?
@thachnnguyen
@thachnnguyen Жыл бұрын
Good explanations. Recommended.
@codetothemoon
@codetothemoon Жыл бұрын
thanks, glad you got something out of it!
@DLPLORD
@DLPLORD Жыл бұрын
Excellent explanation!
@codetothemoon
@codetothemoon Жыл бұрын
Thank you, glad you found it valuable!
@larrybird3729
@larrybird3729 11 ай бұрын
thanks so much!!😍
@codetothemoon
@codetothemoon 11 ай бұрын
thanks for watching, glad you got something out of it!
@Dygear
@Dygear Жыл бұрын
Didn't realize derive clone was making a copy every time I was passing it to a function call. Oh dear. Should probably avoid that in embedded code. Haven't come across lifetimes yet in my own code, but this was very helpful to understand how they should be implemented and why.
@codetothemoon
@codetothemoon Жыл бұрын
Yeah definitely something to be careful with for performance critical apps... I've only had to deal with struct field lifetimes (which I feel like should be inferred by the compiler instead of needing to explicitly specify) in my real world Rust work - haven't had to do it for function parameters yet. Seems like it's not a common need.
@masihaahmadi7663
@masihaahmadi7663 3 ай бұрын
great job 👏🏻
@niksingh710
@niksingh710 5 ай бұрын
hey you are great buddy thanks for this!!
@zeljkomisic5275
@zeljkomisic5275 Жыл бұрын
Best Video today! You are a king! Will try rust again...
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Zelijko! glad you found it valuable!
@pvc988
@pvc988 Жыл бұрын
The cleanest explanation I've seen on YT.
@codetothemoon
@codetothemoon Жыл бұрын
Thanks pvc!
@dimitrisk3525
@dimitrisk3525 Жыл бұрын
You are awesome! Thank you for your videos!
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Dimitris, thanks for watching!
@echobucket
@echobucket Жыл бұрын
This is a really great explanation. My only critique would be to try to make a more real world example than the generic examples. I know that always helps me. But I didn’t understand lifetimes until this video.
@codetothemoon
@codetothemoon Жыл бұрын
thanks echobucket! Yeah maybe I should have gone more real world with the example, it's always a tightrope balancing simplicity and brevity with practicality...
@hos7012
@hos7012 Жыл бұрын
Every time i’m watching any video here i keep , get fantasized about the keyboard sound and the speed of the typing, to the extent that i lose focus on the video 😂
@codetothemoon
@codetothemoon Жыл бұрын
lol - I may have a keyboard video in the works that you may enjoy 😎
@takeiteasyeh
@takeiteasyeh 8 ай бұрын
most make-sense explanation of lifetimes i've seen.
@codetothemoon
@codetothemoon 8 ай бұрын
fantastic, thank you! 😎
@masiafmasiaf2204
@masiafmasiaf2204 Жыл бұрын
thanks for creating this video, i undestand mostly lifestime and reference, borrow is still shallow to me, i started to lean rust, read a few paper of the rust doc, maybe should start writing some simple program to learn those concept
@abraham7966
@abraham7966 Жыл бұрын
I think I found my new favorite Rust channel.
@codetothemoon
@codetothemoon Жыл бұрын
Nice, very happy to have you onboard!
@stea27
@stea27 Жыл бұрын
Great explanation of both cases. The one thing I didn't understand is how do I know when do I need or don't need to use lifetimes? Or will the compiler warn me? I guess I need to read about them again.
@gangov
@gangov Жыл бұрын
thanks a lot for making this
@codetothemoon
@codetothemoon Жыл бұрын
Glad you found it valuable!
@alwin5995
@alwin5995 Жыл бұрын
Been building a project in actix Web with Diesel.....seriously, Diesel is insanely easy to setup and running DB queries on Rust is a charm....
@codetothemoon
@codetothemoon Жыл бұрын
Nice! Yeah it seems like Diesel has a bit of a learning curve especially if you haven't dealt with automatic schema migration before. But it seems pretty nice once you have a handle on everything.
@ChrisHalden007
@ChrisHalden007 Жыл бұрын
Great video. Thanks
@codetothemoon
@codetothemoon Жыл бұрын
Thanks Chris, glad you found it valuable!
@jaromor8808
@jaromor8808 Жыл бұрын
great video, thank you very much, kind sir :)
@codetothemoon
@codetothemoon Жыл бұрын
Thanks for watching, glad you found it valuable!
@Yous0147
@Yous0147 7 ай бұрын
Awesome video, really gave me clarity on both core concepts that I was in proverbly desperate need of. I wish Borrowing and Lifetimes were denoted a bit simpler in the code though, like just seeing an ampersand & is bonkers weird for a newbie and denoting lifetimes with both generics arrows and a single quote? Like, that's weird, and feels obtuse no matter how you slice and dice it (or borrow and mutate it).
Rust's Alien Data Types 👽 Box, Rc, Arc
11:54
Code to the Moon
Рет қаралды 135 М.
You Should Really Know These Traits in Rust
18:36
Oliver Jumpertz
Рет қаралды 10 М.
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
Универ. 10 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:04:59
Комедии 2023
Рет қаралды 2,1 МЛН
but what is 'a lifetime?
12:20
leddoo
Рет қаралды 59 М.
Why i think C++ is better than rust
32:48
ThePrimeTime
Рет қаралды 273 М.
Rust Powered Polymorphism ⚡️ With Traits
9:55
Code to the Moon
Рет қаралды 90 М.
Rust Interior Mutability - Sneaking By The Borrow Checker
16:02
Code to the Moon
Рет қаралды 64 М.
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 285 М.
The Secret to Rust Ownership: Rc vs. Arc
13:47
Flo Woelki
Рет қаралды 1,3 М.
Rust: When C Code Isn't Enough
8:26
CodeAhead
Рет қаралды 153 М.
Rust for TypeScript devs : Borrow Checker
8:49
ThePrimeagen
Рет қаралды 213 М.
Rust: Generics, Traits, Lifetimes
35:34
The Dev Method
Рет қаралды 44 М.
Rust Ownership and Borrowing
38:21
Doug Milford
Рет қаралды 66 М.
Mi primera placa con dios
0:12
Eyal mewing
Рет қаралды 719 М.
ТОП-5 культовых телефонов‼️
1:00
Pedant.ru
Рет қаралды 19 М.
МОЩНЕЕ ТВОЕГО ПК - iPad Pro M4 (feat. Brickspacer)
28:01
ЗЕ МАККЕРС
Рет қаралды 85 М.
Неразрушаемый смартфон
1:00
Status
Рет қаралды 1,2 МЛН
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 2,7 МЛН