1 An [`async`] function used recursion without boxing.
3 Erroneous code example:
5 ```edition2018,compile_fail,E0733
6 async fn foo(n: usize) {
13 To perform async recursion, the `async fn` needs to be desugared such that the
14 `Future` is explicit in the return type:
16 ```edition2018,compile_fail,E0720
17 use std::future::Future;
18 fn foo_desugared(n: usize) -> impl Future<Output = ()> {
21 foo_desugared(n - 1).await;
27 Finally, the future is wrapped in a pinned box:
30 use std::future::Future;
32 fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
35 foo_recursive(n - 1).await;
41 The `Box<...>` ensures that the result is of known size, and the pin is
42 required to keep it in the same place in memory.
44 [`async`]: https://doc.rust-lang.org/std/keyword.async.html