title: tokio-async-await with trait
body: <p>I'd like to write async functions in a trait, but since <code>async fn</code> in traits are not supported yet, I am trying to find the equivalent method interface. This is what I have tried in Rust nightly (2019-01-01):</p>
  
  <p><a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=07038a797e6c140de604f0eac5344d97" rel="noreferrer">playground</a></p>
  
  <pre class="lang-rust prettyprint-override"><code>#![feature(await_macro, async_await, futures_api)]
  #[macro_use]
  extern crate tokio;
  use tokio::prelude::*;
  
  trait T {
      async fn f();
  }
  
  fn main() {
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0706]: trait fns cannot be declared `async`
   --&gt; src/main.rs:7:5
    |
  7 |     async fn f();
    |     ^^^^^^^^^^^^^
  </code></pre>
  
  <p>I read somewhere that <code>async</code> is just <code>impl Future</code>.</p>
  
  <pre class="lang-rust prettyprint-override"><code>trait T {
      fn f() -&gt; impl futures::Future&lt;Item = (), Error = ()&gt;;
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
   --&gt; src/lib.rs:2:15
    |
  2 |     fn f() -&gt; impl futures::Future&lt;Item = (), Error = ()&gt;;
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>Directly returning <code>impl trait</code> is not allowed, so I tried a boxed trait:</p>
  
  <pre class="lang-rust prettyprint-override"><code>trait Resource {
      fn loaded(&amp;self) -&gt; bool;
      fn init(&amp;mut self, auth: &amp;str) -&gt; Box&lt;dyn std::future::Future&lt;Output=()&gt;&gt;;
      fn prepare(&amp;mut self, auth: &amp;str) -&gt; Box&lt;dyn std::future::Future&lt;Output=()&gt;&gt; {
          Box::new(async {
              if !self.loaded() {
                  await!(*(self.init(auth)));
              }
          })
      }
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>[rustc] the size for values of type `dyn std::future::Future&lt;Output=()&gt;` cannot be known at compilation time
  </code></pre>
  
  <p>Without deref, I get the error that no <code>into_awaitable</code> exists for <code>Box&lt;&gt;.</code></p>
  
  <p>Can I use non-Sized <code>impl Future</code> or <code>*Box&lt;Future&gt;</code> with <code>await!</code>? What is the most suitable interface for async functions in the trait?</p>