title: Rust: Passing async function pointers
body: <p>Let's say we have this code:</p>
  <pre class="lang-rust prettyprint-override"><code>fn inc(src: u32) -&gt; u32 {
      src + 1
  }
  
  fn inc2(src: u32) -&gt; u32 {
      src + 2
  }
  
  type Incrementer = fn(u32) -&gt; u32;
  fn increment_printer(inc: Incrementer) {
      println!(&quot;{}&quot;, inc(1));
  }
  
  fn main() {
      increment_printer(inc);
      increment_printer(inc2);
  }
  </code></pre>
  <p>Two functions with the same signature and a 3rd one that accepts pointers for them. Running this code results in 2\n3 being printed.</p>
  <p>But something similar won't compile:</p>
  <pre class="lang-rust prettyprint-override"><code>use core::future::Future;
  
  async fn inc(src: u32) -&gt; u32 {
      src + 1
  }
  
  async fn inc2(src: u32) -&gt; u32 {
      src + 2
  }
  
  type Incrementer = fn(u32) -&gt; dyn Future&lt;Output = u32&gt;;
  async fn increment_printer(inc: Incrementer) {
      println!(&quot;{}&quot;, inc(1).await);
  }
  
  fn main() {
      async {
          increment_printer(inc).await;
          increment_printer(inc2).await;
      }
  }
  </code></pre>
  <pre><code>18 |         increment_printer(inc).await;
     |                           ^^^ expected trait object `dyn Future`, found opaque type
     |
     = note: expected fn pointer `fn(_) -&gt; (dyn Future&lt;Output = u32&gt; + 'static)`
                   found fn item `fn(_) -&gt; impl Future {inc}`
  </code></pre>
  <p>I know that each async function has its own type, as mentioned in the error. Is it possible to force the compiler to forget about the concrete type and treat them as similar types?</p>
  <p>Maybe it's possible to force an async function to return a <code>Box&lt;Future&lt;Output=u32&gt;&gt;</code>?</p>
  <p>I don't want to give up async functions for convenience. Also I don't want to require calling Box::pin() before passing the async function pointer to the function.</p>
  <p>It would be interesting to know if there are more options.</p>