Rust Lifetimes
HTML-код
- Опубликовано: 11 апр 2020
- 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! Наука
This is the best explanation of the lifetime concept that I found on RUclips.
Hey, thanks :)
Easily! I wish I had this when trying to learn the first time around, this makes things much clearer.
Yaaayyyyy!!! I'm glad people are getting so much benefit from this video!
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 !!!
@@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?
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!
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.
2 years ago. Still helping people. Thanks a lot !
Only a few minutes in and it's already more clear than most guides on the net. Thanks!
this is by far the most comprehensive explanation of rust lifetime I have ever seen.
Ah, thanks!
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.
Whoo hoo!!! So glad the video helped :)
Doug, your videos are a fantastic resource! Thank you and have a great day!
You're very welcome! Thanks for the support :)
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!!!
This is absolutely the best explanation of Rust Lifetimes I've found, either on RUclips, online Tutorials or books. Thanks for delivering such a wonderful tutorial video!
thank you for blessing us with your divine intellect.
These videos of Rust by Doug Milford need to be in the official documentation of rust
I learned a lot from this even after reading the rust book. Thank you!
Rustaceans don't look any further, this is the best explanation there is to rust lifetimes!!!
This is the most comprehensive and clear explanation of the concept of lifetime that I have come across on RUclips. Thanks a lot!
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!
I would have quit Rust without this channel. Thank you Doug!!
I've read the chapter 10 of the Rust Programming Language book, but I found the best explanation here.
Thank you so much!
The best explanation I've found on youtube and outside of youtube. Lifetimes never clicked until now, thank you so much!
Thank you very much! that was really helpful.
This is actually the best explaintion of lifetime in whole internet
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.
Ah, thanks!
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.
Really good, thank you. I would love a usecase where you'd WANT to have different lifetimes though.
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?
Well Mr Doug Milford from Lamda valley .. you are one hell of a teacher..
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.
Terrific videos -- clear, well constructed, and weirdly entertaining. Thanks for these!
Great talk that helps to drive the intuitive understanding on Rust’s Lifetimes!
Oh, amazing lesson, you saved my day. Thank you !
Exactly what I needed. So many examples, fast enough so I don't get bored.
Glad you like it :)
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 !
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.
You make a good analogy and it may be helpful to others struggling to understand the concept. Thanks!
Thanks for this!
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!
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.
Yep, yep... my pleasure :)
Thank you so much for your excellent Rust content, Doug. Your videos are the best guides to learning Rust I have found.
Literally the best video or explanation I've seen on lifetimes, including all the usual rust books I've read, thank-you!
Thanks for clarifying on lifetimes, Doug.
Hope you’re doing well since I haven’t seen any recent videos.
These videos are seriously flattening the learning curve... Amazing... Thank you...
Incredible resource for this topic here, thank you for your time!
mithradates channel sent me here, and I am happy for it. This was beautifully explained
Watched this video a couple times and still a bit confused, but a hundred times less confused about lifetimes than I used to be.
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.
Thanks so much! Your explanation solved a lot of issues I've had with this topic.
Thank you so much for this! Very clear, and detailed, even good humor.
This video is pure gold, thanks so much.
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.
Hey, thanks! I'm glad you like them :)
Very thanks for your videos, your teaching skills are amazing. The best Rust learning content I found.
Thanks for the time and effort Doug.
Agreed, best lifetime tutorial on the tubes
Amazing explanation. Thanks Doug!
I am studying Rust and don’t even know why. But this is very interesting (and weird!)
Excellent explanation, no need to check the documentation again for my lifetime 😀
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.
Thanks! Currently working on Macros videos, but I'll move closures/lambdas up the list.
Hi Doug. I've watched all your videos and love the clarity of concept you produce. A natural teacher. Nameste.
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!!!
Thank you! This really helped brush up on my skills!
Very nicely explained!
This was good. Lifetimes are a pain at first, for certain. Thanks for the share.
The best explanation!!
This was an amazing video, thank you so much
You are a god amongst gods. Thank you for this excellent explanation.
thid was super helpful. thank you!
really concise and practical explanation! thanks a lot!
Glad it was helpful!
What a beautiful explanation
Great walkthrough.
Great job. I'm going to share this with a new hire.
WOW, I finally undedrstand frickin lifetimes
Thanks for the great explanation Doug!
Yup, my pleasure!
Doug, you've accomplished what The Rust Book failed to!
Thanks so much for the explanation, subscribed!
Hey, great! I'm glad you liked it so much :)
most helpful video about lifetime
Very nice! Thank you.
wow you do a great a job at breaking down lifetimes, thanks
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!
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 video, you're very coherent. Thank you so much :-)
great tutorial thank u so much 🙏
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.
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
Thank you for the great videos
Thanks! Great video again.
Hey, I appreciate the support :)
You are the best teacher
Thanks so much for doing this video!!!
Sure thing! I'm glad you liked it :)
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
Thats vscode + Rust RLS -> using Rust Analyzer plugin
@@ajinkyax Is rust analyzer available for VIM?
@@secondaryaccount8155 yep! coc.vim + coc-rust-analyzer works like a charm !
Thank you, Sir. This was really helpful.
Yep, yep... glad you like it :)
great video, thx
this man is an absolute sav, tysm!
Looks like you're getting a lot out of the videos. I'm glad!
Félicitation, les tutoriels sont excellents .. Merci
Merci! J'apprécie le compliment.
Thanks a lot!
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.
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.
Sounds like you got some good stuff out of the video. I'm glad!
@@dougmilford7814 definitely! meticulous thing explained in layman terms. thanks again.
Excellent
1:33 - Howdy, partner!)
I certainly enjoyed this talk. wished i watched it earlier :) but still it was informative. tx
Glad you liked it :)
You're a life(time)saver!
I'm glad you liked it :)
thank you so much
excellent!
It's very clear, thank you.
I am having trouble with Macros. Can you have a video to explain it?
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