What if I get Lifetimes Wrong?

Cool.

I appreciate everyone being patient with my pedantic questions. Lifetimes make far more sense now.

Thanks to all,

-kb

1 Like

What an awesome post! Not that my opinion matters, but I liked it a lot, and would love to read more from you. As far as I see, you've got it just right: lifetimes are parts of APIs, and they help to enforce conventions about liveness and borrowing. They are not needed for the code to function correctly, and don't influence it in any way (descriptive, not prescriptive), but they help you write the code correctly. Compare that to C, where, if lucky, you would get the same conventions described in the documentation (if not, you are expected to guess it yourself), and no one would stop you from shooting your foot if you neglect those conventions.

You mean it's easier to write an incorrect program in C than a correct one in Rust? Of course!
If you mean it's easier to write correct programs in C than correct programs in Rust, I'm afraid you're badly mistaken.

Lifetimes are not at all scary once you "get" how they work. Being a newbie myself, I've had a hard time understanding the lifetimes system; unfortunately, there's not enough good explanations out there, the main problem being that to people who understand lifetimes they seem very natural (judging by myself here), so it's hard to explain a thing that's so obvious.

Once I understood them, I wrote my own post to explain how they work, just like you; but my explanation was technical, yours is about generally understanding "why?" -- and I like that, too.

1 Like

Thanks.

-kb