1- ` async fn ` s are not yet supported in Rust.
1+ ` async fn ` s are not yet supported in traits in Rust.
22
33Erroneous code example:
44
@@ -10,7 +10,7 @@ trait T {
1010}
1111```
1212
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:
1414
1515``` edition2018,ignore (example-of-desugaring-equivalence)
1616async fn foo() -> User {
@@ -23,7 +23,7 @@ fn foo(&self) -> impl Future<Output = User> + '_ {
2323```
2424
2525But 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,
2727as it would require [ Generic Associated Types] to be supported:
2828
2929``` edition2018,ignore (example-of-desugaring-equivalence)
@@ -40,8 +40,8 @@ impl MyDatabase {
4040}
4141```
4242
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"
4545(` Pin<Box<dyn Future + Send + 'async>> ` ):
4646
4747``` edition2018,ignore (example-of-desugaring-equivalence)
@@ -75,4 +75,4 @@ You might be interested in visiting the [async book] for further information.
7575[ `async-trait` crate ] : https://crates.io/crates/async-trait
7676[ async-is-hard ] : https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/
7777[ 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