Hi there !
I've some questions about the lifetimes syntax. I understand the need and importance of this feature in rust, but I definitely don't understand what I write when I handle these in my Rust code. I've read the part of the book about the lifetimes, but it's not enough for me to understand
If I well understand : each definition of variables come with its own lifetime, which relies generally on the scope of this variable. At first sight, the compiler may handle the lifetime when we are not using references in function (by example) because not using references mean that we give ownership of the resources to the function arguments.
But, what is the "by default" behaviour ? By example :
fn function1(b: bool, s: usize) -> u32
{ ... }
1/ Can we use explicit lifetimes annotations for this ? Is it useful?
Other question, in this code :
fn function2<'a>(b: &'a bool) -> &'a bool
2/ What do we do ? If I well understood, our annotations don't change the real lifetimes associated with the variables, it's just "for compilier understanding" annotations. But : which parts of these 'a are definitions ? Which parts of these are necessary informations ? Indeed : we have three 'a
. But I assume they have different meanings. What are they ?
So, I'm totally lost with the lifetimes annotations syntax. If someone could clarify it, I would be grateful.
Solution
All the conversation is interesting for whom doesn't understand lifetimes. thanks to alice !