Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The function may be a good example, but this blog post doesn't really do a good job at explaining it, at least not to people unfamiliar with Rust (which I assume it's aimed at). If I understood correctly, if you assign the lifetime 'a (or 'x, 'l, whatever) to all parameters, you tell the compiler that they all have the same lifetime? And if you wanted to have different lifetimes, you could use 'a and 'b? But the article doesn't explicitly mention that, so you could end up thinking that 'a is some kind of a magical constant that you have to use...


The target audience was programmers who are at least familiar with the basic concepts of stack, heap, and pointers, including but not limited to newer Rust programmers.

You make a good point about 'a; I could have made that clearer. In practice it works the same way as a generic type (the letter is arbitrary, and it's declared inside the < >), which I assumed people would be familiar with, but I can see how the connection between the two may not have been obvious.


You can still edit it to improve it in that regard. Maybe add a footnote or something.


Yes, I plan to go back and make several improvements this evening after I'm off work :)


Yep, you’re correct. Naming the first (especially when it’s also the only) lifetime parameter ’a is just a convention, like naming the first type parameter T.


That's a good point. When I first started trying to learn Rust, I also thought that there was some semantic meaning to 'a, since everyone uses that exact same name in all the examples.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: