title: Writing a generic trait implementation with IntoIterator trait, but only for immutable reference implementors
body: <p>I am defining a trait that takes in a <code>i: &amp;I</code> parameter. I would like to use this <code>i</code> value in a <code>for</code> loop.</p>
  
  <p>For example:</p>
  
  <pre><code>struct Test;
  
  trait Bar&lt;I&gt; {
      fn bar(&amp;self, i: &amp;I);
  }
  
  impl&lt;T, I: IntoIterator&lt;Item=T&gt;&gt; Bar&lt;I&gt; for Test {
      fn bar(&amp;self, i: &amp;I) {
          for x in i {
              println!("woo!");
          }
      }
  }
  
  fn main() {
      let vec = vec!(1, 2, 3);
      let test = Test;
      test.bar(&amp;vec);
  }
  </code></pre>
  
  <p><a href="http://is.gd/OkuUHo" rel="nofollow">Playground link</a></p>
  
  <p>This results in the error:</p>
  
  <pre><code>&lt;anon&gt;:10:9: 12:10 error: the trait `core::iter::Iterator` is not implemented for the type `&amp;I` [E0277] &lt;anon&gt;:10         for x in i { &lt;anon&gt;:11             println!("woo!"); &lt;anon&gt;:12         } &lt;anon&gt;:10:9: 12:10 help: see the detailed explanation for E0277 &lt;anon&gt;:10:9: 12:10 note: `&amp;I` is not an iterator; maybe try calling `.iter()` or a similar method &lt;anon&gt;:10:9: 12:10 note: required by `core::iter::IntoIterator::into_iter` error: aborting due to previous error playpen: application terminated with error code 101
  </code></pre>
  
  <p>I was playing around with using the <code>Deref</code> trait to see if I could get something to work, but to no avail.</p>
  
  <p>I would really like to keep the immutable reference in the function definition as this trait is attempting to be generic over many types, and defining the other implementations using <code>Bar&lt;&amp;'a I&gt;</code> has lead to some other lifetime related issues that I have been having trouble with as well.</p>