title: How do you extend a trait like itertools does with collect_vec()?
body: <p>I would like to create a method similar to the <code>collect_vec()</code> function in <code>itertools</code>.</p>
  <p>Creating a small example by copying the <code>itertools</code> code:</p>
  <pre><code>pub trait MyItertools: Iterator {
      fn collect_vec(self) -&gt; Vec&lt;Self::Item&gt;
          where Self: Sized
      {
          self.collect()
      }
  }
  
  fn main() {
      let v = (0..5).collect_vec();
      println!(&quot;{:?}&quot;, v);
  }
  </code></pre>
  <p>I rather naively expect that the compiler will use my <code>collect_vec</code> as
  <code>MyItertools</code> is in scope.</p>
  <p>There must be some other magic that <code>itertools</code> is doing to get this to compile.</p>
  <p>We get the error:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0599]: no method named `collect_vec` found for struct `std::ops::Range&lt;{integer}&gt;` in the current scope
    --&gt; src/main.rs:14:20
     |
  14 |     let v = (0..5).collect_vec();
     |                    ^^^^^^^^^^^ method not found in `std::ops::Range&lt;{integer}&gt;`
     |
     = help: items from traits can only be used if the trait is implemented and in scope
  note: `MyItertools` defines an item `collect_vec`, perhaps you need to implement it
    --&gt; src/main.rs:5:1
     |
  5  | pub trait MyItertools: Iterator {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
  error: aborting due to previous error
  </code></pre>
  <p>Which is misleading as we have indeed implemented <code>collect_vec</code> in <code>MyItertools</code>.</p>
  <p>One possible solution is to <code>impl MyItertools</code> for all flavours of
  <code>Iterator</code>, but there does not seem to be a way to do this for all <code>Iterator</code> implementing traits and types.</p>