'a is the lifetime parameter in both cases. This is a kind of general parameter, so each use of Type or each use of get_text can choose a different "value" for this general parameter. Actual lifetimes are never chosen by an explicit programmer, unless you use 'static .
The compiler will output what 'a should be for each Type value or for every use of get_text .
impl<'a> introduces a new lifetime parameter for the entire impl block. Then it is used in the type: impl<'a> Type<'a> { .. }
Exactly what 'a means depends on how it is used in the Type definition. From your example, I think Type :
struct Type<'a> { x: &'a u32, }
This definition reads: For each 'a lifetime, define a type containing the reference x: &'a u32 . Thus, Type is generic and can store a link with any lifetime.
impl<'a> Type<'a> { .. } reads: For each lifetime 'a define methods for the type Type<'a> .
Since we now know the definition of the Type structure, we know that the 'a parameter inside the impl block is always equal to the link lifetime in the Type x field.
One that has a return type โ & 'a u32 indicates that a variable that receives the return value should not die earlier ... to what? Before a Type object dies?
'a is the lifetime of the link stored inside the Type<'a> value, and it has nothing to do with the type value itself. The only rule is that 'a must survive the value of the type itself, because it is not allowed to store the link beyond its end. So we can stick with this &'a u32 until at least the point where the Type value dies and maybe more.
impl TextEditor {
This is really common. &self is a reference to the value self - borrowing, and the get_text method get_text again a common element. It has one common parameter - the parameter of the lifetime.
It reads for any lifetime, 'a borrows itself as a link &'a self (a reference to this lifetime) and returns a reference to a String with the same lifetime.
Using the same parameter both on input &self and on output &String means that they are connected, and Rust will consider itself as borrowed until the returned reference to String is returned.
Again, the get_text method is generic, and the compiler will select a 'value' for 'a for each use of the method. This is a method that can return differently long string entries, depending on how long you let it take self . Sometimes it chooses a long life, so you can hold the returned &String long time. In some cases, using get_text will use a shorter lifetime if you do not use the return value at all.
In this case, since we see that &'a String tied directly to borrowing &'a self the TextEditor value, we know that we can only support a reference to String for as long as we can hold the borrow value of TextEditor .