title: How to avoid excessive cloning in Rust?
body: <p>I'm trying to learn Rust, and like many before me set off to write a Fibonacci sequence iterator for practice.  My first pass used <code>u32</code>s and worked fine, so I decided to try to write a generic version.  This is my result:</p>
  
  <pre><code>use num::Integer;
  use std::ops::Add;
  
  pub struct Fibonacci&lt;T: Integer + Add + Clone&gt; {
      nth: T,
      n_plus_one_th: T,
  }
  
  impl&lt;T: Integer + Add + Clone&gt; Iterator for Fibonacci&lt;T&gt; {
      type Item = T;
      fn next(&amp;mut self) -&gt; Option&lt;T&gt; {
          let temp = self.nth.clone();
          self.nth = self.n_plus_one_th.clone();
          self.n_plus_one_th = temp.clone() + self.n_plus_one_th.clone();
          Some(temp)
      }
  }
  
  impl&lt;T: Integer + Add + Clone&gt; Fibonacci&lt;T&gt; {
      pub fn new() -&gt; Fibonacci&lt;T&gt; {
          Fibonacci {
              nth: T::one(),
              n_plus_one_th: T::one(),
          }
      }
  }
  </code></pre>
  
  <p>I tested this with a <code>u32</code> and a <code>num::BigUint</code>, and it works fine.  I'm concerned about all the cloning in the <code>next</code> method though.  In particular, I don't understand why I need to clone during the addition step.</p>
  
  <p>I suspect there is a better way to write this using some of Rust's more advanced reference concepts, but so far I haven't figured it out.</p>