You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/closure-expr.md
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,20 @@ Closures marked with the `async` keyword indicate that they are asynchronous in
42
42
43
43
Calling the async closure does not perform any work, but instead evaluates to a value that implements [`Future`] that corresponds to the computation of the body of the closure.
44
44
45
+
```rust
46
+
asyncfntakes_async_callback(f:implAsyncFn(u64)) {
47
+
f(0).await;
48
+
f(1).await;
49
+
}
50
+
51
+
asyncfnexample() {
52
+
takes_async_callback(async|i| {
53
+
core::future::ready(i).await;
54
+
println!("done with {i}.");
55
+
}).await;
56
+
}
57
+
```
58
+
45
59
> **Edition differences**: Async closures are only available beginning with Rust 2018.
0 commit comments