Rust Lifetimes
Ғылым және технология
An introduction to Rust Lifetimes through example.
In addition to this video, Arseniy Kucherenko has made an addendum to this video talking about static lifetimes. Very informative! I recommend you check it out.
• Additional examples to...
This Rust programming language tutorial series is aimed at easing your training step by step. Rust is a systems level language aimed at speed and safety and can be run cross-platform, including embedded systems and even the browser with WebAssembly (WASM)! I use the VS Code development environment to help you learn the core topics. Please join me on this journey with this fantastic new programming language.
Topics include coding basics, hello world, primitives, cargo, toml, rustup, arrays, borrowing, shadowing, string vs str, tuples, enumerations (enums), println and so much more...all free on youtube!
Пікірлер: 217
This is the best explanation of the lifetime concept that I found on KZread.
@dougmilford7814
4 жыл бұрын
Hey, thanks :)
@Mephistel
4 жыл бұрын
Easily! I wish I had this when trying to learn the first time around, this makes things much clearer.
@dougmilford7814
4 жыл бұрын
Yaaayyyyy!!! I'm glad people are getting so much benefit from this video!
@karuma1959
4 жыл бұрын
Absolutely! Thanks Doug, for putting so much work into your Rust tutorials. I've seen tutorials from other people before but this is by far the best! I will definetly recommend it !!!
@dougmilford7814
4 жыл бұрын
@@karuma1959 Awesome! Thanks for helping my channel gain traction. I appreciate it :)
hands-down the best RUST videos for beginners on youtube.
Even after 3 years, this is still the best explanation there is to rust lifetimes, any chance we'll be seeing a smart pointer, declarative and procedural macros explanation?
The best explanation on Lifetimes. I referred a Oreilly book, a nostarch book and spent a entire day. Could not comprehend. This video did it.
Only a few minutes in and it's already more clear than most guides on the net. Thanks!
I love the way you explain the details of Rust, satisfy me a lot
I read the rust book over and over and didn't understand it until I watched this video. Thank you sir!
2 years ago. Still helping people. Thanks a lot !
Fantastic explanation, especially by showing the "unnecessary" parts that the compiler usually does automatically. It helped me fix my TryFrom implementation within a minute, and it's much clearer to me now.
@dougmilford7814
4 жыл бұрын
Whoo hoo!!! So glad the video helped :)
I have to agree with many of the comments already here... best explanation I found of lifetimes. I think that possibly, maybe, could be that I might understand lifetimes now ;) Thanks Doug!
Rustaceans don't look any further, this is the best explanation there is to rust lifetimes!!!
this is by far the most comprehensive explanation of rust lifetime I have ever seen.
@dougmilford7814
4 жыл бұрын
Ah, thanks!
what a fantastic coverage of lifetimes in rust. I'm here after reading the section in the rust book and watching this cleared up most of the issues I had with what I read in the book. thank you for this!!!
Doug, your videos are a fantastic resource! Thank you and have a great day!
@dougmilford7814
4 жыл бұрын
You're very welcome! Thanks for the support :)
This is absolutely the best explanation of Rust Lifetimes I've found, either on KZread, online Tutorials or books. Thanks for delivering such a wonderful tutorial video!
Thank you very much! that was really helpful. This is actually the best explaintion of lifetime in whole internet
Oh, amazing lesson, you saved my day. Thank you !
Dough, you’re doing a fantastic job with these videos. I usually prefer written materials but when the book doesn’t explain something clearly, your video is usually the answer.
@dougmilford7814
4 жыл бұрын
Ah, thanks!
This is the most comprehensive and clear explanation of the concept of lifetime that I have come across on KZread. Thanks a lot!
I learned a lot from this even after reading the rust book. Thank you!
I would have quit Rust without this channel. Thank you Doug!!
Since 3 days I was researching about lifetimes on the articles, and then I saw your video.. It is the only best explained resource that I could find on the internet.. A simple thanks would not be enough to express the time and effort you saved me, learning this concept. And it is such a beautifully explained concept, that I hope that you don't delete this video, or make it private. I would be bookmarking this video on my notes app.
These videos of Rust by Doug Milford need to be in the official documentation of rust
The best explanation I've found on youtube and outside of youtube. Lifetimes never clicked until now, thank you so much!
Awesome! Doug's videos are of high quality and condensed with valuable content. Doug is a fantastic educator with unusual abilities to keep you up and focused. This video comes right on time and happens to be very helpful to me in `digesting` the notorious Rust Book. Thanks Doug.
@dougmilford7814
4 жыл бұрын
Yep, yep... my pleasure :)
mithradates channel sent me here, and I am happy for it. This was beautifully explained
Well Mr Doug Milford from Lamda valley .. you are one hell of a teacher..
Thanks for clarifying on lifetimes, Doug. Hope you’re doing well since I haven’t seen any recent videos.
I've read the chapter 10 of the Rust Programming Language book, but I found the best explanation here. Thank you so much!
This video is pure gold, thanks so much.
thank you for blessing us with your divine intellect.
this is absolutely brilliant! i had no idea that every reference has a lifetime, that it is implicitly inserted, and that it is different for every reference. knowing this makes rust lifetimes a much easier topic to understand and handle. it is also quite logical. thanks a lot!
Agreed, best lifetime tutorial on the tubes
The whole serie on Rust is greatly educational ! Very clear explanation, straight to the point, best tutorials on Rust I have found. Thank you for the great content !
Incredible resource for this topic here, thank you for your time!
Literally the best video or explanation I've seen on lifetimes, including all the usual rust books I've read, thank-you!
Awesome. Your video tutorials are just awesome. Looking forward to and hoping your next topic is "Rust closures/lambdas". Don't forget to inject humors in your videos. They're great.
@dougmilford7814
4 жыл бұрын
Thanks! Currently working on Macros videos, but I'll move closures/lambdas up the list.
Excellent explanation, no need to check the documentation again for my lifetime 😀
This was great. I tried a few videos, a few examples, and tried to read the Rust book. But this video was so clear, had many examples (much appreciated), not complicated, and to the point. I was able to follow along, write the codes myself, and take notes and not get tired, bored, or lost. Great job. Will come back for more.
Exactly what I needed. So many examples, fast enough so I don't get bored.
@dougmilford7814
4 жыл бұрын
Glad you like it :)
Lifetimes are an integral part of any reference type, although it's often hidden. Any reference can easily be converted (downcast?) to a reference of shorter lifetime. That's why a single generic lifetime, like fn testtwo { one } else { two } } fn main() { let a = "hello"; { let b = "world"; { let c = test(a, b); println!("{}", c); } \\ c dies here } \\ b dies here } \\ a dies here works, even though there are three distinct lifetimes for the three variables. As a and b are passed into the function, a is downcast to a reference with the lifetime of b as it is bound to the variable one. This makes the inputs have the same lifetime, as required. The return therefore has the same lifetime: the lifetime of b. When the returned reference is bound to c, it gets downcast to have the lifetime of c. This isn't to disagree with anything you said. But I don't think it was mentioned explicitly, and coming to this realization is what made lifetimes in function signatures click for me. I do wish this video had existed two years ago, though. Would've helped me out a lot.
@dougmilford7814
4 жыл бұрын
You make a good analogy and it may be helpful to others struggling to understand the concept. Thanks!
@fastexpand
Жыл бұрын
Thanks for this!
Really good, thank you. I would love a usecase where you'd WANT to have different lifetimes though.
@sachin__ak
2 жыл бұрын
did you understand the part where he passed a const variable and a normal variable to a function with same lifetime 'a? const was outside the main function and has lifetime of the program and normal variable inside the function has a lifetime of main fn, how can that be equal? is it because main is the last function to exit the stack and the program ends so rust considers the variable declared inside main fn to be the same lifetime of 'static?
Great talk that helps to drive the intuitive understanding on Rust’s Lifetimes!
Thanks for the insightful explanations! I have been going through all of your Rust videos and your explanations are super clear and to the point.
@dougmilford7814
4 жыл бұрын
Hey, thanks! I'm glad you like them :)
Terrific videos -- clear, well constructed, and weirdly entertaining. Thanks for these!
Thank you so much for your excellent Rust content, Doug. Your videos are the best guides to learning Rust I have found.
Thanks so much! Your explanation solved a lot of issues I've had with this topic.
Amazing explanation. Thanks Doug!
Thanks for the time and effort Doug.
1:33 - Howdy, partner!)
These videos are seriously flattening the learning curve... Amazing... Thank you...
Thank you so much for this! Very clear, and detailed, even good humor.
Watched this video a couple times and still a bit confused, but a hundred times less confused about lifetimes than I used to be.
@dougmilford7814
4 жыл бұрын
Yeah, it's a very tricky topic. Except for creating Macros, I would say it's the toughest topic to wrap your head around in Rust. Hopefully you learned enough to at least be functional. I think a lot of learning it is running into situations and thinking about why you're getting a compile error. Let me know if you run into any specific situations that are giving you trouble and perhaps I can speak directly to that. Sometimes a specific example is what's needed to help clear the fog.
WOW, I finally undedrstand frickin lifetimes
Very thanks for your videos, your teaching skills are amazing. The best Rust learning content I found.
I am studying Rust and don’t even know why. But this is very interesting (and weird!)
Great job. I'm going to share this with a new hire.
Thank you! This really helped brush up on my skills!
Hi Doug. I've watched all your videos and love the clarity of concept you produce. A natural teacher. Nameste.
@dougmilford7814
4 жыл бұрын
Thanks, Mage! I'm really glad you liked them :)
I watched every second of all your rust tutorial series. I would like if you make a video about . closure ( inline function ). Great Work!!!
really concise and practical explanation! thanks a lot!
@dougmilford7814
4 жыл бұрын
Glad it was helpful!
This was good. Lifetimes are a pain at first, for certain. Thanks for the share.
Very nicely explained!
What a beautiful explanation
most helpful video about lifetime
these series are too good. I would love to watch a video to learn more about you, how you got involved with Rust, how you learned it, etc. This is some quality content. So thanks!! Question: Do you have a plan to do any videos on Actix web?
Great walkthrough.
Hey, great videos and nice job on the vocal recordings! You forgot to put a link to the memory management video in the description :) or maybe you didn’t think about it, but it would be nice!
Doug, you've accomplished what The Rust Book failed to! Thanks so much for the explanation, subscribed!
@dougmilford7814
4 жыл бұрын
Hey, great! I'm glad you liked it so much :)
This was an amazing video, thank you so much
thid was super helpful. thank you!
Thanks for the great explanation Doug!
@dougmilford7814
4 жыл бұрын
Yup, my pleasure!
The best explanation!!
You are a god amongst gods. Thank you for this excellent explanation.
You are the best teacher
Very nice! Thank you.
Very nice and clear lecture. At 15:20, I think it would be more appropriate to say that the lifetimes of the parameters passed in are known to outlast the function, because the caller (or someone up the call stack) has the ownership. I.e., it's not because you're not returning a reference, but because you can't deallocate the memory the input reference refers to from inside the function. You necessarily have to return from the function (and drop the reference) before the caller will have a chance to deallocate what the reference was pointing to. If you passed in both the reference and ownership, you could do that, but you wouldn't be able to because of the only-one-mutable rule.
@dougmilford7814
4 жыл бұрын
Hey, Darren, thanks! I appreciate it :) The Lifetime of reference parameters passed in for sure outlast the function. So I agree with you on that. If you never return the reference parameter via the output, though, I'm not sure you'll ever get a lifetime issue. Returning the reference is what causes the compile error because of the potential issue of using the resultant reference after memory gets cleaned up (lifetimes are always there in the background... it's just not necessary to make the developer handle them in many situations). I'm not 100% sure what you mean about passing in both the reference and ownership. But maybe I'm just not understanding. If I somehow misinterpreted your question/comment, let me know. I think you're trying to make a good point. I'm just not sure if I fully understand. Maybe if you gave an example that would help me understand? And, if I misspeak at some point, I appreciate when people catch me and correct it in the comments. I do my best to be thorough and correct, but now and then everyone has a slip of the tongue. So thank you for helping clarify if there's confusion :) Doug
Hey Doug, this is really helpful. Could you please make a video explaining the Smart Pointers in Rust?
I love how you can write rust without even having to compile and check if everything works
@ajinkyax
4 жыл бұрын
Thats vscode + Rust RLS -> using Rust Analyzer plugin
@secondaryaccount8155
4 жыл бұрын
@@ajinkyax Is rust analyzer available for VIM?
@evilmorty-tv1xs
4 жыл бұрын
@@secondaryaccount8155 yep! coc.vim + coc-rust-analyzer works like a charm !
wow you do a great a job at breaking down lifetimes, thanks
Thank you for the great videos
Thanks! Great video again.
@dougmilford7814
4 жыл бұрын
Hey, I appreciate the support :)
great tutorial thank u so much 🙏
Thanks so much for doing this video!!!
@dougmilford7814
4 жыл бұрын
Sure thing! I'm glad you liked it :)
Great video, you're very coherent. Thank you so much :-)
this is owsome explaination , you can think to create the full course on rust on udemy or pluralsight , currently there is no course available which explain with this ammount of detials you shared . thanks for your effort
this has taken me months to understand but i'm finally getting there I think
Doug, 'a is great, never knew, Thanks for sharing your insights.
@dougmilford7814
4 жыл бұрын
Sounds like you got some good stuff out of the video. I'm glad!
@googiek9351
4 жыл бұрын
@@dougmilford7814 definitely! meticulous thing explained in layman terms. thanks again.
Awesome videos! Many thanks for your time and these truly valuable videos that you share with Rust community. And if there is any possibility to increase the font size of your editor (VScode) in your videos, much to the better.
great video, thx
this man is an absolute sav, tysm!
@dougmilford7814
4 жыл бұрын
Looks like you're getting a lot out of the videos. I'm glad!
Thank you, Sir. This was really helpful.
@dougmilford7814
4 жыл бұрын
Yep, yep... glad you like it :)
I certainly enjoyed this talk. wished i watched it earlier :) but still it was informative. tx
@dougmilford7814
4 жыл бұрын
Glad you liked it :)
Thanks a lot!
Félicitation, les tutoriels sont excellents .. Merci
@dougmilford7814
4 жыл бұрын
Merci! J'apprécie le compliment.
Excellent
You're a life(time)saver!
@dougmilford7814
4 жыл бұрын
I'm glad you liked it :)
Hi Doug, Your videos are helping me a lot. I'd suggest you to increase the font size. Thank you.
@dougmilford7814
3 жыл бұрын
Yeah, the Lifetimes video I totally goofed. I recorded the whole thing and only saw the issue right before I was about to publish. You're not the first to notice on this video that the font's too small.
thank you so much
It's very clear, thank you. I am having trouble with Macros. Can you have a video to explain it?