title: Returning reference from a function in Rust
body: <p>Following is a program that returns the reference to the largest value of any given vector.I used generics for this, but does not work.</p>
  <pre><code>fn largest&lt;T : PartialOrd&gt;(vec : &amp;[T]) -&gt; &amp;T{
  
  let mut biggest = vec[0];
   
  for &amp;item in vec{
      if item &gt; biggest{
          biggest = item
      }
   }
  
   &amp;biggest
  }
  </code></pre>
  <p>I know I am returning a reference to a local variable, so It won't compile. The other solution is to use <code>copy</code> trait like,</p>
  <pre><code>fn largest&lt;T : PartialOrd + Copy&gt;(vec : &amp;[T]) -&gt; T{}
  </code></pre>
  <p>Is there any way so that I can return the reference and avoid using <code>Copy</code> trait?</p>