| 1 |
use async_stream::stream; |
| 2 |
use futures_util::StreamExt; |
| 3 |
|
| 4 |
use std::pin::pin; |
| 5 |
|
| 6 |
macro_rules! asynk { |
| 7 |
($e:expr) => { |
| 8 |
async { $e } |
| 9 |
}; |
| 10 |
} |
| 11 |
|
| 12 |
#[tokio::main] |
| 13 |
async fn main() { |
| 14 |
pin!(stream! { |
| 15 |
let yield_42 = asynk!(yield 42_usize); |
| 16 |
let s = stream! { |
| 17 |
yield Box::new(12345); |
| 18 |
yield_42.await; // yield 42 -- wait that's not a Box!? |
| 19 |
}; |
| 20 |
for await (n, i) in s.enumerate() { |
| 21 |
println!("Item at index {n}:\n {i}"); |
| 22 |
// Item at index 0: |
| 23 |
// 12345 |
| 24 |
// Item at index 1: |
| 25 |
// Segmentation fault |
| 26 |
} |
| 27 |
}) |
| 28 |
.next() |
| 29 |
.await; |
| 30 |
} |