title: Is it possible to send closures via channels?
body: <p>I would like to send a closure via channels:</p>
  
  <pre><code>use std::thread;
  use std::sync::mpsc;
  
  #[derive(Debug)]
  struct Test {
      s1: String,
      s2: String,
  }
  
  fn main() {
      let t = Test {
          s1: "Hello".to_string(),
          s2: "Hello".to_string(),
      };
      let (tx, rx) = mpsc::channel::&lt;FnOnce(&amp;mut Test)&gt;();
      thread::spawn(move || {
          let mut test = t;
          let f = rx.recv().unwrap();
          f(&amp;mut test);
          println!("{:?}", test);
      });
      tx.send(move |t: &amp;mut Test| {
          let s = "test".to_string();
          t.s1 = s;
      });
  }
  </code></pre>
  
  <p>(<a href="https://play.rust-lang.org/?gist=c5fdf840e6c6dd6ef903621d3bedbcfd&amp;version=stable" rel="noreferrer">playground</a>)</p>
  
  <p>I get a bunch of errors:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test): std::marker::Sized` is not satisfied
    --&gt; src/main.rs:15:20
     |
  15 |     let (tx, rx) = mpsc::channel::&lt;FnOnce(&amp;mut Test)&gt;();
     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test)` does not have a constant size known at compile-time
     |
     = help: the trait `std::marker::Sized` is not implemented for `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test)`
     = note: required by `std::sync::mpsc::channel`
  
  error[E0277]: the trait bound `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test): std::marker::Sized` is not satisfied
    --&gt; src/main.rs:15:20
     |
  15 |     let (tx, rx) = mpsc::channel::&lt;FnOnce(&amp;mut Test)&gt;();
     |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test)` does not have a constant size known at compile-time
     |
     = help: the trait `std::marker::Sized` is not implemented for `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test)`
     = note: required by `std::sync::mpsc::Sender`
  
  error[E0599]: no method named `recv` found for type `std::sync::mpsc::Receiver&lt;for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test)&gt;` in the current scope
    --&gt; src/main.rs:18:20
     |
  18 |         let f = rx.recv().unwrap();
     |                    ^^^^
     |
     = note: the method `recv` exists but the following trait bounds were not satisfied:
             `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test) : std::marker::Sized`
  
  error[E0599]: no method named `send` found for type `std::sync::mpsc::Sender&lt;for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test)&gt;` in the current scope
    --&gt; src/main.rs:22:8
     |
  22 |     tx.send(move |t: &amp;mut Test| {
     |        ^^^^
     |
     = note: the method `send` exists but the following trait bounds were not satisfied:
             `for&lt;'r&gt; std::ops::FnOnce(&amp;'r mut Test) : std::marker::Sized`
  </code></pre>
  
  <p>It seems that <code>FnOnce</code> is not sendable but I don't understand why.</p>