title: Result<T, E> Type in Rust. why reference can't be passed as T or E?
body: <p>I'm new to rust and lately I read about Result type.
  loved the concept and started using it in my app.</p>
  <p>My first try was with &amp;str. So my return type looked like this:</p>
  <pre><code>pub fn calculate_risk_score(a: i32, b: i32) -&gt; Result&lt;i32, &amp;str&gt; {
      return Ok(a + b);
  }
  </code></pre>
  <p>and thats the error I was getting:</p>
  <p><a href="https://i.stack.imgur.com/EUCtp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EUCtp.png" alt="compilation error" /></a></p>
  <p>The following code works:</p>
  <pre><code>pub fn calculate_risk_score(a: i32, b: i32) -&gt; Result&lt;i32, &amp;'static str&gt; {
      return Ok(a + b);
  }
  </code></pre>
  <p>Now I don't think I fully get why it's wrong to pass a reference as a generic type. Besides I don't understand why static solves the problem and I don't fully understand the explanation about named lifetime parameter.
  I read those articles but I think Im still missing something.</p>
  <p><a href="https://doc.rust-lang.org/std/result/" rel="nofollow noreferrer">https://doc.rust-lang.org/std/result/</a></p>
  <p><a href="https://doc.rust-lang.org/rust-by-example/scope/lifetime/static_lifetime.html" rel="nofollow noreferrer">https://doc.rust-lang.org/rust-by-example/scope/lifetime/static_lifetime.html</a></p>
  <p>so my questions:</p>
  <ol>
  <li>why does &amp;'static str can be passed as generic type while &amp;str can't?</li>
  <li>what it has to do with lifetime? and why does the compiler can't figure out how long the reference is valid when I set it to be &amp;str?</li>
  </ol>