liveBook · Manning

Static lifetime

As explained in Idiomatic Rust

The Rust lifetime that lasts for the entire duration of the program.

In Rust, `'static` is a lifetime that lasts for the entire program. String literals have this lifetime, so they can be returned as `&'static str` without needing an explicit annotation. section 2.1.5

Return a string literal

fn message() -> &'static str { "hello" } section 2.1.5

How Idiomatic Rust covers it

How deep it goes
Defines `'static` and notes string-literal returns, without developing further lifetime mechanics.
Examples
Demonstrates a string literal returned with the type `&'static str`.
What you can do after
Understand why string literals can be returned as `&'static str`.
How it connects
Connects `'static` to references, lifetime parameters, and string literals.

Also explained in

Compare how 2 books explain static lifetime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Idiomatic Rust. The section links point to the parts of the book it draws on.