Need clarity on passing strings to functions

When I do this:

fn print_me(msg: &str) {
    println!("msg = {}", msg);

pub fn main() {

All is well, but I'm passing a reference to a string literal, not a variable having a lifetime elsewhere. What happens to the reference after the function finishes? Does the lifetime of the string literal end after the function completes?

The string literal has type &'static str since it's a reference to the UTF-8 encoded text data packed with the program binary itself. This portion of memory will not be unloaded until the process be terminated, hence the 'static lifetime means.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.