Comments by "p11" (@porky1118) on "How to Learn Rust" video.
-
9:55 When I was new to Rust, I didn't fear using references, even if they had lifetime annotations. Now, years later, I try to avoid explicit lifetimes alltogether and only use them if there is no chance to avoid them.
But there are a few cases where I really want lifetime annotations, especially in structs. Normally when I want some kind of accessor to some data, which should not be modified or go out of scope as long as the accessor exists.
For example I used this to call some function safely. Calling the function is only safe if I specify a valid parameter. So instead of calling the function directly, I created a struct, which lists all valid parameters, and in order to call it, I only specify the index of the parameter I want to call.
But iterators are also a good example for this.
3