Skip to content

Commit a82e5dd

Browse files
MajorBreakfastboats
authored andcommitted
Ordering of async move keywords
1 parent 17e9fbc commit a82e5dd

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

text/0000-async_await.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ fn main() {
119119
This will print both "Hello from main" statements before printing "Hello from
120120
async closure."
121121

122+
`async` closures can be annotated with `move` to capture ownership of the
123+
variables they close over.
124+
122125
## `async` blocks
123126

124127
You can create a future directly as an expression using an `async` block:
@@ -240,7 +243,7 @@ fn foo<'a>(arg1: &'a str, arg2: &str) -> impl Future<Output = usize> + 'a {
240243
// do some initialization using arg2
241244

242245
// closure which is evaluated immediately
243-
move async {
246+
async move {
244247
// asynchronous portion of the function
245248
}
246249
}
@@ -265,6 +268,19 @@ This is not a literal expansion, because the `yield` concept cannot be
265268
expressed in the surface syntax within `async` functions. This is why `await!`
266269
is a compiler builtin instead of an actual macro.
267270

271+
## The order of `async` and `move`
272+
273+
Async closures and blocks can be annotated with `move` to capture ownership of
274+
the variables they close over. The order of the keywords is fixed to
275+
`async move`. Permitting only one ordering avoids confusion about whether it is
276+
significant for the meaning.
277+
278+
```rust
279+
async move {
280+
// body
281+
}
282+
```
283+
268284
# Drawbacks
269285
[drawbacks]: #drawbacks
270286

0 commit comments

Comments
 (0)