Skip to content

Commit 8e4e068

Browse files
committed
Make a case for box async fn
1 parent 37242cb commit 8e4e068

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/vision/roadmap/async_fn/boxable.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,25 @@ async fn foo() { }
2727
```
2828

2929
This does not have to desugar to `-> Box<dyn Future<...>>`; it can instead desugar to `Box<impl Future>`, or perhaps a nominal type to permit recursion.
30+
31+
Another approach is the `box` keyword:
32+
33+
```rust
34+
box async fn foo() { }
35+
```
36+
37+
We can apply the keyword modifier to async blocks and closures:
38+
39+
```rust
40+
fn foo() -> BoxFuture<Output = ()> {
41+
box async { ... }
42+
}
43+
```
44+
45+
```rust
46+
async fn stuff(s: impl AsyncIterator) {
47+
s.map(box async |x| { ... })
48+
}
49+
```
50+
51+
This is useful for breaking up future types to make them more shallow.

0 commit comments

Comments
 (0)