File: for_await.rs

package info (click to toggle)
rust-async-stream 0.3.4-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 216 kB
  • sloc: makefile: 2
file content (23 lines) | stat: -rw-r--r-- 433 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use async_stream::stream;

use futures_util::stream::StreamExt;

#[tokio::test]
async fn test() {
    let s = stream! {
        yield "hello";
        yield "world";
    };

    let s = stream! {
        for await x in s {
            yield x.to_owned() + "!";
        }
    };

    let values: Vec<_> = s.collect().await;

    assert_eq!(2, values.len());
    assert_eq!("hello!", values[0]);
    assert_eq!("world!", values[1]);
}