title: Why can't I return an &str value generated from a String?
body: <p>I'm having some trouble trying to grasp why I can't return an <code>&amp;str</code> value generated from a <code>String</code> (goodness, when will <code>as_str</code> be ready?) and I'm doing something wrong. I get this idea because nothing that I do makes the value live long enough to use.</p>
  
  <p>I'm trying to implement <code>error::Error</code> for a custom struct:</p>
  
  <pre><code>impl error::Error for LexicalError {
      fn description(&amp;self) -&gt; &amp;str {
          let s = format!("{}", self);
  
          // s doesn't live long enough to do this, I've tried 
          // cloning s and using that, but still the clone doesn't
          // live long enough.
          s.trim()
      }
  
      fn cause(&amp;self) -&gt; Option&lt;&amp;error::Error&gt; {
          None
      }
  }
  </code></pre>
  
  <p>(for the complete snippet, here is the <a href="http://is.gd/i9OM9L" rel="noreferrer">playpen</a>)</p>
  
  <p>I can't figure out how to return an &amp;str from <code>description</code>, I'd like to reuse the <code>Display</code> logic, unless of course I'm completely misunderstanding what <code>description</code> should be returning (perhaps the short description of the issue). Either, I get the same issue with the return of <code>format!(...)</code> which is a variable I can't seem to get to live long enough to be useful to me.</p>