title: Why does a generic method inside a trait require trait object to be sized?
body: <p>I have this code (<a href="https://play.rust-lang.org/?gist=44d0f4ac393f7244d29780e43b702fb1&amp;version=stable&amp;backtrace=0" rel="noreferrer">playground</a>):</p>
  
  <pre><code>use std::sync::Arc;
  
  pub trait Messenger : Sync + Send {
      fn send_embed&lt;F: FnOnce(String) -&gt; String&gt;(&amp;self, u64, &amp;str, f: F)
          -&gt; Option&lt;u64&gt; where Self: Sync + Send;
  }
  
  struct MyMessenger {
      prefix: String,
  }
  impl MyMessenger {
      fn new(s: &amp;str) -&gt; MyMessenger {
          MyMessenger { prefix: s.to_owned(), }
      }
  }
  impl Messenger for MyMessenger {
      fn send_embed&lt;F: FnOnce(String) -&gt; String&gt;(&amp;self, channel_id: u64, text: &amp;str, f: F) -&gt; Option&lt;u64&gt; {
          println!("Trying to send embed: chid={}, text=\"{}\"", channel_id, text);
          None
      }
  
  }
  
  struct Bot {
      messenger: Arc&lt;Messenger&gt;,
  }
  impl Bot {
      fn new() -&gt; Bot {
          Bot {
              messenger: Arc::new(MyMessenger::new("HELLO")),
          }
      }
  }
  
  fn main() {
      let b = Bot::new();
  }
  </code></pre>
  
  <p>I wanted to make a polymorphic object (trait <code>Messenger</code> and one of polymorphic implementations is <code>MyMessenger</code>). But when I try to compile it I have an error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0038]: the trait `Messenger` cannot be made into an object
    --&gt; &lt;anon&gt;:25:5
     |
  25 |     messenger: Arc&lt;Messenger&gt;,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Messenger` cannot be made into an object
     |
     = note: method `send_embed` has generic type parameters
  </code></pre>
  
  <p>I have found that I must require <code>Sized</code> in this case, but this does not solve it. If I change my <code>send_embed</code> method to the following:</p>
  
  <pre><code>fn send_embed&lt;F: FnOnce(String) -&gt; String&gt;(&amp;self, u64, &amp;str, f: F)
      -&gt; Option&lt;u64&gt; where Self: Sized + Sync + Send;
  </code></pre>
  
  <p>Then it compiles successfully but:</p>
  
  <ol>
  <li>Why do we need <code>Sized</code> here? This violates polymorphism if we can not use this method from a trait object.</li>
  <li><p>We actually can't use this method from <code>Arc&lt;Messenger&gt;</code> then:</p>
  
  <pre><code>fn main() {
      let b = Bot::new();
      b.messenger.send_embed(0u64, "ABRACADABRA", |s| s);
  }
  </code></pre>
  
  <p>Gives:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the trait bound `Messenger + 'static: std::marker::Sized` is not satisfied
    --&gt; &lt;anon&gt;:37:17
     |
  37 |     b.messenger.send_embed(0u64, "ABRACADABRA", |s| s);
     |                 ^^^^^^^^^^ the trait `std::marker::Sized` is not implemented for `Messenger + 'static`
     |
     = note: `Messenger + 'static` does not have a constant size known at compile-time
  </code></pre></li>
  </ol>
  
  <p>I am totally stuck here. No idea how to use polymorphism with generic method in a trait. Is there a way?</p>