1
- ` async fn ` s are not yet supported in Rust.
1
+ ` async fn ` s are not yet supported in traits in Rust.
2
2
3
3
Erroneous code example:
4
4
@@ -10,7 +10,7 @@ trait T {
10
10
}
11
11
```
12
12
13
- ` async fn ` s normally return an ` impl Future ` , making the following two examples equivalent:
13
+ ` async fn ` s return an ` impl Future ` , making the following two examples equivalent:
14
14
15
15
``` edition2018,ignore (example-of-desugaring-equivalence)
16
16
async fn foo() -> User {
@@ -23,7 +23,7 @@ fn foo(&self) -> impl Future<Output = User> + '_ {
23
23
```
24
24
25
25
But when it comes to supporting this in traits, there are [ a few implementation
26
- issues] [ async-is-hard ] , one of which is that returning ` impl Trait ` in traits is not supported,
26
+ issues] [ async-is-hard ] . One of them is returning ` impl Trait ` in traits is not supported,
27
27
as it would require [ Generic Associated Types] to be supported:
28
28
29
29
``` edition2018,ignore (example-of-desugaring-equivalence)
@@ -40,8 +40,8 @@ impl MyDatabase {
40
40
}
41
41
```
42
42
43
- Until these issues are resolved, you can use the [ ` async-trait ` crate] , which allows you to use
44
- this feature by sidesteping the language feature issue by desugaring to "boxed futures"
43
+ Until these issues are resolved, you can use the [ ` async-trait ` crate] , allowing you to use
44
+ ` async fn ` in traits by desugaring to "boxed futures"
45
45
(` Pin<Box<dyn Future + Send + 'async>> ` ):
46
46
47
47
``` edition2018,ignore (example-of-desugaring-equivalence)
@@ -75,4 +75,4 @@ You might be interested in visiting the [async book] for further information.
75
75
[ `async-trait` crate ] : https://crates.io/crates/async-trait
76
76
[ async-is-hard ] : https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/
77
77
[ Generic Associated Types ] : https://github.com/rust-lang/rust/issues/44265
78
- [ async book ] : https://rust-lang.github.io/async-book/07_workarounds/06_async_in_traits.html
78
+ [ async book ] : https://rust-lang.github.io/async-book/07_workarounds/06_async_in_traits.html
0 commit comments