title: Proper way to return a new string in Rust
body: <p>I just spent a week reading the Rust Book, and now I'm working on my first program, which returns the filepath to the system wallpaper:</p>
  
  <pre><code>pub fn get_wallpaper() -&gt; &amp;str {
      let output = Command::new("gsettings");
      // irrelevant code
      if let Ok(message) = String::from_utf8(output.stdout) {
          return message;
      } else {
          return "";
      }
  }
  </code></pre>
  
  <p>I'm getting the error <code>expected lifetime parameter on &amp;str</code> and I know Rust wants an input <code>&amp;str</code> which will be returned as the output because any <code>&amp;str</code> I create inside the function will be cleaned up immediately after the function ends.</p>
  
  <p>I know I can sidestep the issue by returning a <code>String</code> instead of a <code>&amp;str</code>, and many answers to similar questions have said as much. But I can also seemingly do this:</p>
  
  <pre><code>fn main() {
      println!("message: {}", hello_string(""));
  }
  
  fn hello_string(x: &amp;str) -&gt; &amp;str {
      return "hello world";
  }
  </code></pre>
  
  <p>to get a <code>&amp;str</code> out of my function. Can someone explain to me why this is bad and why I should never do it? Or maybe it's not bad and okay in certain situations?</p>