Lifetimes of String Literals

When we covered references we mentioned the idea of a lifetime, and that a reference could not outlive the data it was borrowing. There’s something cool about string literals; since the data they reference is part of the program itself, we know that a reference to them will be valid as long as the program is running. Therefore, we give these things a special lifetime called 'static. Lifetimes are usually optional, but we’re free to add them in if desired:

Get hands-on with 1200+ tech skills courses.