Skip to content

Commit

Permalink
Remove desugared async-trait example
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank authored Nov 19, 2019
1 parent 846f5e6 commit a079159
Showing 1 changed file with 1 addition and 22 deletions.
23 changes: 1 addition & 22 deletions src/librustc_error_codes/error_codes/E0706.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a079159

Please sign in to comment.