| 1 | use async_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 crate/::fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().; |
| 2 | use futures_utilrust-analyzer cargo futures-util 0.3.34 crate/::{pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!, Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream#, StreamExtrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#}; |
| 3 | |
| 4 | fn build_streamrust-analyzer cargo async-fn-stream 0.3.2 build_stream().() -> impl Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream#<Itemrust-analyzer cargo futures-core 0.3.34 stream/Stream#Item# = i32> { |
| 5 | fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move { |
| 6 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#3 { |
| 7 | // yield elements from stream via `emitter` |
| 8 | emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(i).rust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'_, T>`][Future]poll().awaitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'_, T>`][Future]poll().; |
| 9 | } |
| 10 | }) |
| 11 | } |
| 12 | |
| 13 | async fn examplerust-analyzer cargo async-fn-stream 0.3.2 example().() { |
| 14 | let stream = build_streamrust-analyzer cargo async-fn-stream 0.3.2 build_stream().(); |
| 15 | |
| 16 | pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream); |
| 17 | let mut numbers = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 18 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(number) = stream.nextrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#next().().rust-analyzer cargo futures-util 0.3.34 stream/stream/next/impl#[`Next<'_, St>`][Future]poll().awaitrust-analyzer cargo futures-util 0.3.34 stream/stream/next/impl#[`Next<'_, St>`][Future]poll(). { |
| 19 | printrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/print!!("{number} "); |
| 20 | numbers.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(number); |
| 21 | } |
| 22 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(); |
| 23 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(numbers, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0, 1, 2]); |
| 24 | } |
| 25 | |
| 26 | pub fn mainrust-analyzer cargo async-fn-stream 0.3.2 main().() { |
| 27 | futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(examplerust-analyzer cargo async-fn-stream 0.3.2 example().()); |
| 28 | } |