From the course: Rust Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Static lifetime - Rust Tutorial
From the course: Rust Essential Training
Static lifetime
- [Instructor] There is a lifetime name that's reserved in Rust for special purposes, and that is static. The static lifetime indicates that data is available for the entire duration of a program. That data never gets dropped, so you can safely reference it at any time. For example, the text for a string literal is stored directly in the program's binary, so it never goes away. That data is available from start to finish. Therefore, all string literals have a static lifetime, which can be annotated as shown here. The static lifetime can be associated with a reference to indicate that it will never become invalid and that it lives longer than any other lifetime. However, references that have a static lifetime such as string literals can be coerced to other more restrictive lifetimes if that reference is passed as the output parameter from a function with another lifetime annotation, though that's rarely done. You may also…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.