Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ordering of async move keywords
  • Loading branch information
MajorBreakfast committed Apr 24, 2018
commit bcd934a59fc6c2c4f3b2e860c2a56aecbcf2b117
18 changes: 17 additions & 1 deletion text/0000-async_await.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ fn main() {
This will print both "Hello from main" statements before printing "Hello from
async closure."

`async` closures can be annotated with `move` to capture ownership of the
variables they close over.

## `async` blocks

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

// closure which is evaluated immediately
move async {
async move {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should move go before async for consistency with closures?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagined that closures would also be written async move |x| { ... }.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, that's a different kind of consistency that may be more important? Overall as long as we have a consistent ordering everywhere I'm happy. (Just dealt with the lack of an enforced ordering in C++...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. We don't have const or unsafe closures so async would be first. I think async move, const move, unsafe move works nicely. πŸ‘

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const unsafe async move |x| { ... }

// asynchronous portion of the function
}
}
Expand All @@ -265,6 +268,19 @@ This is not a literal expansion, because the `yield` concept cannot be
expressed in the surface syntax within `async` functions. This is why `await!`
is a compiler builtin instead of an actual macro.

## The order of `async` and `move`

Async closures and blocks can be annotated with `move` to capture ownership of
the variables they close over. The order of the keywords is fixed to
`async move`. Permitting only one ordering avoids confusion about whether it is
significant for the meaning.

```rust
async move {
// body
}
```

# Drawbacks
[drawbacks]: #drawbacks

Expand Down