Skip to content

Commit

Permalink
Adjust documents
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed May 4, 2019
1 parent d94fd0d commit 4f59a41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions futures-async-macro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
futures-preview = { version = "0.3.0-alpha.14", features = ["async-stream", "nightly"] }
futures-preview = { version = "0.3.0-alpha.15", features = ["async-stream", "nightly"] }
```

### \#\[for_await\]
Expand All @@ -17,6 +17,7 @@ Processes streams using a for loop.
This is a reimplement of [futures-await]'s `#[async]` for loops for futures 0.3 and is an experimental implementation of [the idea listed as the next step of async/await](https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#for-await-and-processing-streams).

```rust
#![feature(async_await, generators, stmt_expr_attributes, proc_macro_hygiene)]
use futures::for_await;
use futures::prelude::*;

Expand All @@ -26,13 +27,16 @@ for value in stream::iter(1..=5) {
}
```

`value` has the `Item` type of the stream passed in. Note that async for loops can only be used inside of `async` functions or `#[async_stream]` functions.
`value` has the `Item` type of the stream passed in. Note that async for loops can only be used inside of `async` functions, closures, blocks, `#[async_stream]` functions and `async_stream_block!` macros.

### \#\[async_stream\]

Creates streams via generators.

This is a reimplement of [futures-await]'s `#[async_stream]` for futures 0.3 and is an experimental implementation of [the idea listed as the next step of async/await](https://github.com/rust-lang/rfcs/blob/master/text/2394-async_await.md#generators-and-streams).

```rust
#![feature(async_await, generators)]
use futures::prelude::*;
use futures::async_stream;

Expand Down
3 changes: 3 additions & 0 deletions futures-async-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod error;

mod elision;

/// Processes streams using a for loop.
#[proc_macro_attribute]
pub fn for_await(args: TokenStream, input: TokenStream) -> TokenStream {
assert_!(args.is_empty(), args_is_not_empty!("for_await"));
Expand All @@ -28,6 +29,7 @@ pub fn for_await(args: TokenStream, input: TokenStream) -> TokenStream {
Expand(Future).fold_expr(Expr::ForLoop(expr)).into_token_stream().into()
}

/// Creates streams via generators.
#[proc_macro_attribute]
pub fn async_stream(args: TokenStream, input: TokenStream) -> TokenStream {
assert_!(args.is_empty(), args_is_not_empty!("async_stream"));
Expand Down Expand Up @@ -180,6 +182,7 @@ fn expand_async_stream_fn(item: ItemFn) -> TokenStream {
})
}

/// Creates streams via generators.
#[proc_macro]
pub fn async_stream_block(input: TokenStream) -> TokenStream {
let input = TokenStream::from(TokenTree::Group(Group::new(Delimiter::Brace, input)));
Expand Down

0 comments on commit 4f59a41

Please sign in to comment.