1 Recursion in an `async fn` requires boxing. For example, this will not compile:
3 ```edition2018,compile_fail,E0733
4 async fn foo(n: usize) {
11 To achieve async recursion, the `async fn` needs to be desugared
12 such that the `Future` is explicit in the return type:
14 ```edition2018,compile_fail,E0720
15 use std::future::Future;
16 fn foo_desugared(n: usize) -> impl Future<Output = ()> {
19 foo_desugared(n - 1).await;
25 Finally, the future is wrapped in a pinned box:
28 use std::future::Future;
30 fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
33 foo_recursive(n - 1).await;
39 The `Box<...>` ensures that the result is of known size,
40 and the pin is required to keep it in the same place in memory.