Remove desugared async-trait
example
This commit is contained in:
parent
846f5e6bb9
commit
a079159c64
1 changed files with 1 additions and 22 deletions
|
@ -42,28 +42,7 @@ impl MyDatabase {
|
||||||
|
|
||||||
Until these issues are resolved, you can use the [`async-trait` crate], allowing you to use
|
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"
|
`async fn` in traits by desugaring to "boxed futures"
|
||||||
(`Pin<Box<dyn Future + Send + 'async>>`):
|
(`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!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that using these trait methods will result in a heap allocation per-function-call. This is not
|
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
|
a significant cost for the vast majority of applications, but should be considered when deciding
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue