title: Turn generic method into trait object safe method
body: <p>I would like to make an adapter that removes generic parameters (to produce a trait object) as in the example below.</p>
  <pre><code>use std::ops::Deref;
  
  fn make_dyn_box&lt;I, S&gt;(iter_in: I)
  where
      I: Iterator&lt;Item = S&gt;,
      S: Deref&lt;Target = u8&gt;,
  {
      let mut iter_out = iter_in.map(
          |s| -&gt; Box&lt;dyn Deref&lt;Target = u8&gt;&gt; {Box::new(s)}
      );
      take_dyn_box(&amp;mut iter_out)
  }
  
  fn take_dyn_box&lt;'a: 'b, 'b&gt;(
      iter: &amp;'a mut (dyn 'a + Iterator&lt;Item = Box&lt;dyn 'b + Deref&lt;Target = u8&gt;&gt;&gt;),
  ) { }
  </code></pre>
  <p>Is there a way to accomplish this without a heap allocation, using only safe code, and no external dependencies?</p>
  <p>The below is an idea of what I want, but the borrow checker doesn't allow this.</p>
  <pre><code>use std::ops::Deref;
  
  fn make_dyn&lt;I, S&gt;(iter_in: I)
  where
      I: Iterator&lt;Item = S&gt;,
      S: Deref&lt;Target = u8&gt;,
  {
      let mut item = None;
      let item = &amp;mut item;
      let mut iter_out = iter_in.map(|s| -&gt; &amp;dyn Deref&lt;Target = u8&gt; {
          item.replace(s);
          Option::as_ref(item).unwrap()
      });
      take_dyn(&amp;mut iter_out)
  }
  
  fn take_dyn&lt;'a: 'b, 'b&gt;(
      iter: &amp;'a mut (dyn 'a + Iterator&lt;Item = &amp;'b (dyn 'b + Deref&lt;Target = u8&gt;)&gt;),
  ) { }
  </code></pre>