title: cannot move a value of type dyn for<'r> FnOnce(&'r mut [u8]): the size of dyn for<'r> FnOnce(&'r mut [u8]) cannot be statically determined
body: <p>I'm trying to have a function shared between threads, that can be called with another function on it:</p>
  <pre><code>fn main() {
      let on_virtual_tun_write = std::sync::Arc::new(|f: &amp;dyn FnOnce(&amp;mut [u8]), size: usize|-&gt; std::result::Result&lt;(),()&gt;{
          let mut buffer = vec![0; size];
          f(buffer.as_mut_slice());
          Ok(())
      });
  }
  </code></pre>
  <p>Once it's called, it uses the <code>f</code> passed as an argument, to retrieve a buffer. As you can see, I do not intend to copy the function, I just use it as soon as someone calls the closure, and discards it. However, Rust thinks that I want to copy it. What can I do to tell Rust that I just want to use a reference to the function? I thought <code>&amp;dyn</code> was sufficient.</p>
  <p>Error:</p>
  <pre><code>error[E0161]: cannot move a value of type dyn for&lt;'r&gt; FnOnce(&amp;'r mut [u8]): the size of dyn for&lt;'r&gt; FnOnce(&amp;'r mut [u8]) cannot be statically determined
   --&gt; src/main.rs:4:9
    |
  4 |         f(buffer.as_mut_slice());
    |         ^
  
  error[E0507]: cannot move out of `*f` which is behind a shared reference
   --&gt; src/main.rs:4:9
    |
  4 |         f(buffer.as_mut_slice());
    |         ^ move occurs because `*f` has type `dyn for&lt;'r&gt; FnOnce(&amp;'r mut [u8])`, which does not implement the `Copy` trait
  
  error: aborting due to 2 previous errors; 1 warning emitted
  </code></pre>