1
Fork 0

Remove desugared async-trait example

This commit is contained in:
Esteban Kuber 2019-11-19 11:29:20 -08:00 committed by GitHub
parent 846f5e6bb9
commit a079159c64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,28 +42,7 @@ impl MyDatabase {
Until these issues are resolved, you can use the [`async-trait` crate], allowing you to use
`async fn` in traits by desugaring to "boxed futures"
(`Pin<Box<dyn Future + Send + 'async>>`):
```edition2018,ignore (example-of-desugaring-equivalence)
#[async_trait]
impl MyDatabase {
async fn get_user(&self) -> User {
unimplemented!()
}
}
// The annotated impl above gets desugared as follows:
impl MyDatabase {
fn get_user<'async>(
&'async self,
) -> Pin<Box<dyn std::future::Future<Output = User> + Send + 'async>>
where
Self: Sync + 'async,
{
unimplemented!()
}
}
```
(`Pin<Box<dyn Future + Send + 'async>>`).
Note that using these trait methods will result in a heap allocation per-function-call. This is not
a significant cost for the vast majority of applications, but should be considered when deciding