From 6c1b4a5edc7db29df8ad03712eabaa4e9898378b Mon Sep 17 00:00:00 2001 From: Zicklag Date: Fri, 27 Mar 2020 17:11:11 -0500 Subject: [PATCH] Add Async Recursion Macro to Workarounds --- src/07_workarounds/05_recursion.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/07_workarounds/05_recursion.md b/src/07_workarounds/05_recursion.md index dee60fd7..29eaa5cd 100644 --- a/src/07_workarounds/05_recursion.md +++ b/src/07_workarounds/05_recursion.md @@ -55,3 +55,19 @@ to make `recursive` into a non-`async` function which returns a `.boxed()` ```rust,edition2018 {{#include ../../examples/07_05_recursion/src/lib.rs:example}} ``` + +## Using a Macro + +There is also a community-developed macro, [`async-recursion`](https://github.com/dcchut/async-recursion), that can be used to automatically transform an async function to return a boxed future: + +```rust +use async_recursion::async_recursion; + +#[async_recursion] +async fn recursive() { + recursive().await; + recursive().await; +} +``` + +This allows the function to recurse without you having to manually change the method signature and body.