The static lifetime, written 'static, lasts for the entire program. A string literal such as "I live forever!" is stored directly in the binary, so its type is &'static str. A borrowed reference to a String usually has a shorter lifetime. section 10.1
Returning a string literal
A function may safely return a string literal: fn works() -> &'static str { "I live forever!" } It may not return a reference to a String created inside the function. That String disappears when the function ends, leaving an invalid reference. When the compiler suggests &'static str, it means the function must return data that really lives for the whole program; the annotation does not make temporary data live longer. section 10.2.1
Using 'static in a type is a restriction, not a lifetime-extending command. For example, a struct with name: &'static str accepts string literals but rejects a reference into a local String. Use a named lifetime such as struct City<'a> with name: &'a str when the reference only needs to live as long as the struct. section 10.2.2
Keep these practical distinctions in mind:
- Use &'static str for data known to remain available for the entire program, especially string literals. section 10.1
- Do not use 'static merely to silence a borrowing error; choose an owned String or an appropriate shorter lifetime instead. section 10.2.1 section 10.2.2
- Regular spawned threads require captured items to have a 'static lifetime, while scoped threads avoid that requirement when their scope eventually ends. section 12.6

