Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 #![doc = include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("../README.md")]
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
4 cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::{Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#, UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#},
5 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::{RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#, UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#},
6 pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#,
7 syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#,
8 taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::{Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#, Wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Waker#},
9 };
10
11 use futures_utilrust-analyzer cargo futures-util 0.3.34 crate/::{Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#, Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream#};
12 use pin_project_literust-analyzer cargo pin-project-lite 0.2.17 crate/::pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!;
13 use smallvecrust-analyzer cargo smallvec 1.15.2 crate/::SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#;
14
15 /// An intermediary that transfers values from stream to its consumer
16 pub struct StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T> {
17 innerrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#inner.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<T>>>,
18 }
19
20 /// An intermediary that transfers values from stream to its consumer
21 pub struct TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E> {
22 innerrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#inner.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>>>,
23 }
24
25 thread_localrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/thread_local!! {
26 /// A type-erased pointer to the `Inner<_>`, for which a call to `Stream::poll_next` is active.
27 static ACTIVE_STREAM_INNERrust-analyzer cargo async-fn-stream 0.3.2 ACTIVE_STREAM_INNER.: Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#<*const ()> = const { Cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/Cell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]new().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null().()) };
28 }
29
30 /// A guard that ensures that `ACTIVE_STREAM_INNER` is returned to its previous value even in case of a panic.
31 struct ActiveStreamPointerGuardrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard# {
32 old_ptrrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard#old_ptr.: *const (),
33 }
34
35 impl ActiveStreamPointerGuardrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard# {
36 fn set_active_ptrrust-analyzer cargo async-fn-stream 0.3.2 impl#[ActiveStreamPointerGuard]set_active_ptr().(ptr: *const ()) -> Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[ActiveStreamPointerGuard] {
37 let old_ptr = ACTIVE_STREAM_INNERrust-analyzer cargo async-fn-stream 0.3.2 ACTIVE_STREAM_INNER..withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/impl#[`LocalKey<T>`]with().(|thread_ptr| thread_ptr.replacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]replace().(ptr));
38 Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[ActiveStreamPointerGuard] { old_ptrrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard#old_ptr. }
39 }
40 }
41
42 impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for ActiveStreamPointerGuardrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard# {
43 fn droprust-analyzer cargo async-fn-stream 0.3.2 impl#[ActiveStreamPointerGuard][Drop]drop().(&mut self) {
44 ACTIVE_STREAM_INNERrust-analyzer cargo async-fn-stream 0.3.2 ACTIVE_STREAM_INNER..withrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/impl#[`LocalKey<T>`]with().(|thread_ptr| thread_ptr.setrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`Cell<T>`]set().(self.old_ptrrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard#old_ptr.));
45 }
46 }
47
48 /// SAFETY:
49 /// `Inner<T>` stores the state shared between `StreamEmitter`/`TryStreamEmitter` and `FnStream`/`TryFnStream`.
50 /// It is stored within `Arc<UnsafeCell<_>>`. Exclusive access to it is controlled using:
51 /// 1) exclusive reference `Pin<&mut FnStream>` which is provided to `FnStream::poll_next`
52 /// 2) `ACTIVE_STREAM_INNER`, which is itself managed by `FnStream::poll_next`.
53 /// - `ACTIVE_STREAM_INNER` is only set when the corresponding `Pin<&mut FnStream>` is on the stack
54 /// - `EmitFuture` can safely access its inner reference if it equals to `ACTIVE_STREAM_INNER` (all other accesses are invalid and lead to panics)
55 struct Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<T> {
56 // `stream_waker` is used to compare the waker of the stream future with the waker of the `Emit` future.
57 // If the stream implementation does not have sub-executors, we don't have to push wakers to `pending_wakers`, which avoids cloning it.
58 stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Waker#>,
59 // Due to internal concurrency, a single call to stream's future may yield multiple elements.
60 // All elements are stored here and yielded from the stream before polling the future again.
61 pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#<[T; 1]>,
62 pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#<[Wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Waker#; 1]>,
63 }
64
65 // SAFETY: `FnStream` implements own synchronization
66 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut> {}
67 // SAFETY: `FnStream` implements own synchronization
68 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()> + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut> {}
69 impl<T: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()> + UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#> UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe# for FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut> {}
70 impl<T: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()> + RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#> RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#
71 for FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut>
72 {
73 }
74 // SAFETY: `TryFnStream` implements own synchronization
75 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, E: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#
76 for TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut>
77 {
78 }
79 // SAFETY: `TryFnStream` implements own synchronization
80 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, E: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>> + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#
81 for TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut>
82 {
83 }
84 impl<T: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#, E: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>> + UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#> UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#
85 for TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut>
86 {
87 }
88 impl<T: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#, E: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>> + RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#>
89 RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe# for TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut>
90 {
91 }
92 // SAFETY: `StreamEmitter` implements own synchronization
93 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T> {}
94 // SAFETY: `StreamEmitter` implements own synchronization
95 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T> {}
96 impl<T: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#> UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe# for StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T> {}
97 impl<T: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#> RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe# for StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T> {}
98 // SAFETY: `TryStreamEmitter` implements own synchronization
99 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, E: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E> {}
100 // SAFETY: `TryStreamEmitter` implements own synchronization
101 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#, E: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E> {}
102 impl<T: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#, E: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#> UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe# for TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E> {}
103 impl<T: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#, E: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#> RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe# for TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E> {}
104 // SAFETY: `EmitFuture` implements own synchronization.
105 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# for EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, T> {}
106 // SAFETY: `EmitFuture` implements own synchronization
107 unsafe impl<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#> Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# for EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, T> {}
108 impl<T: UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe#> UnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/UnwindSafe# for EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, T> {}
109 impl<T: RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe#> RefUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/RefUnwindSafe# for EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, T> {}
110
111 pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!! {
112 /// Implementation of [`Stream`] trait created by [`fn_stream`].
113 pub struct FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()>> {
114 #[pin]
115 futrust-analyzer cargo async-fn-stream 0.3.2 FnStream#fut.: Fut,
116 innerrust-analyzer cargo async-fn-stream 0.3.2 FnStream#inner.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<T>>>,
117 }
118 }
119
120 /// Create a new infallible stream which is implemented by `func`.
121 ///
122 /// Caller should pass an async function which will return successive stream elements via [`StreamEmitter::emit`].
123 ///
124 /// # Example
125 ///
126 /// ```rust
127 /// use async_fn_stream::fn_stream;
128 /// use futures_util::Stream;
129 ///
130 /// fn build_stream() -> impl Stream<Item = i32> {
131 /// fn_stream(|emitter| async move {
132 /// for i in 0..3 {
133 /// // yield elements from stream via `emitter`
134 /// emitter.emit(i).await;
135 /// }
136 /// })
137 /// }
138 /// ```
139 pub fn fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().<T, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()>>(
140 func: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T>) -> Fut,
141 ) -> FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut> {
142 FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#::newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`]new().(func)
143 }
144
145 impl<T, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()>> FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut> {
146 fn newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`]new().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T>) -> Fut>(func: F) -> Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`] {
147 let inner = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]new().(Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner# {
148 stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
149 pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#::newrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]new().(),
150 pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#::newrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]new().(),
151 }));
152 let emitter = StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter# {
153 innerrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#inner.: inner.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(),
154 };
155 let fut = func(emitter);
156 Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`] { futrust-analyzer cargo async-fn-stream 0.3.2 FnStream#fut., innerrust-analyzer cargo async-fn-stream 0.3.2 FnStream#inner. }
157 }
158 }
159
160 impl<T, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()>> Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream# for FnStreamrust-analyzer cargo async-fn-stream 0.3.2 FnStream#<T, Fut> {
161 type Itemrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`][Stream]Item# = T;
162
163 fn poll_nextrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`][Stream]poll_next().(
164 self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`][Stream]>,
165 cx: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>,
166 ) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`][Stream]::Itemrust-analyzer cargo futures-core 0.3.34 stream/Stream#Item#>> {
167 let this = self.projectrust-analyzer cargo async-fn-stream 0.3.2 impl#[`FnStream<T, Fut>`]project().();
168
169 // SAFETY:
170 // (see safety comment for `Inner<T>`)
171 // 1) we have no aliasing, since we're holding unique reference to `Self`, and
172 // 2) `this.inner` is not deallocated for the duration of this method
173 let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
174 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = inner.pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values..poprust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]pop().() {
175 return Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value));
176 }
177 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().inner.pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers..is_emptyrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]is_empty().() {
178 for waker in inner.pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers..drainrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]drain().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#) {
179 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().waker.will_wakerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker]will_wake().(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().()) {
180 waker.wakerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker]wake().();
181 }
182 }
183 }
184 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stream_waker) = inner.stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() {
185 stream_waker.clone_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker][Clone]clone_from().(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().());
186 } else {
187 inner.stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker][Clone]clone().());
188 }
189
190 // SAFETY: ensure that we're not holding a reference to this.inner
191 _ = inner;
192
193 // SAFETY for Inner<T>:
194 // - `ACTIVE_STREAM_INNER` now contains valid pointer to `this.inner` during the call to `fut.poll`
195 // - `ACTIVE_STREAM_INNER` is restored after the call due to the use of guard
196 let polling_ptr_guard =
197 ActiveStreamPointerGuardrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard#::set_active_ptrrust-analyzer cargo async-fn-stream 0.3.2 impl#[ActiveStreamPointerGuard]set_active_ptr().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::as_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`]as_ptr().(&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner.).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().());
198 let r = this.futrust-analyzer cargo async-fn-stream 0.3.2 Projection#fut..pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().(cx);
199 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(polling_ptr_guard);
200
201 // SAFETY:
202 // (see safety comment for `Inner<T>`)
203 // 1) we have no aliasing, since:
204 // - we're holding unique reference to `Self`, and
205 // - we removed the pointer from `ACTIVE_STREAM_INNER`
206 // 2) `this.inner` is not deallocated for the duration of this method
207 let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
208
209 match r {
210 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(()) => Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
211 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending# => {
212 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = inner.pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values..poprust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]pop().() {
213 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value))
214 } else {
215 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending#
216 }
217 }
218 }
219 }
220 }
221
222 /// Create a new fallible stream which is implemented by `func`.
223 ///
224 /// Caller should pass an async function which can:
225 ///
226 /// - return successive stream elements via [`TryStreamEmitter::emit`]
227 /// - return transient errors via [`TryStreamEmitter::emit_err`]
228 /// - return fatal errors as [`Result::Err`]
229 ///
230 /// # Example
231 /// ```rust
232 /// use async_fn_stream::try_fn_stream;
233 /// use futures_util::Stream;
234 ///
235 /// fn build_stream() -> impl Stream<Item = Result<i32, anyhow::Error>> {
236 /// try_fn_stream(|emitter| async move {
237 /// for i in 0..3 {
238 /// // yield elements from stream via `emitter`
239 /// emitter.emit(i).await;
240 /// }
241 ///
242 /// // return errors view emitter without ending the stream
243 /// emitter.emit_err(anyhow::anyhow!("An error happened"));
244 ///
245 /// // return errors from stream, ending the stream
246 /// Err(anyhow::anyhow!("An error happened"))
247 /// })
248 /// }
249 /// ```
250 pub fn try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().<T, E, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>>>(
251 func: impl FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E>) -> Fut,
252 ) -> TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut> {
253 TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#::newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`]new().(func)
254 }
255
256 pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!! {
257 /// Implementation of [`Stream`] trait created by [`try_fn_stream`].
258 pub struct TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>>> {
259 is_errrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#is_err.: bool,
260 #[pin]
261 futrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#fut.: Fut,
262 innerrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#inner.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>>>,
263 }
264 }
265
266 impl<T, E, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>>> TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut> {
267 fn newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`]new().<F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E>) -> Fut>(func: F) -> Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`] {
268 let inner = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]new().(Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner# {
269 stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
270 pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#::newrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]new().(),
271 pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers.: SmallVecrust-analyzer cargo smallvec 1.15.2 SmallVec#::newrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]new().(),
272 }));
273 let emitter = TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter# {
274 innerrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#inner.: inner.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(),
275 };
276 let fut = func(emitter);
277 Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`] {
278 is_errrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#is_err.: false,
279 futrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#fut.,
280 innerrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#inner.,
281 }
282 }
283 }
284
285 impl<T, E, Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>>> Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream# for TryFnStreamrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#<T, E, Fut> {
286 type Itemrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`][Stream]Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>;
287
288 fn poll_nextrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`][Stream]poll_next().(
289 self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`][Stream]>,
290 cx: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>,
291 ) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`][Stream]::Itemrust-analyzer cargo futures-core 0.3.34 stream/Stream#Item#>> {
292 // TODO: merge the implementation with `FnStream`
293 if self.is_errrust-analyzer cargo async-fn-stream 0.3.2 TryFnStream#is_err. {
294 return Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
295 }
296 let this = self.projectrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryFnStream<T, E, Fut>`]project().();
297 // SAFETY:
298 // (see safety comment for `Inner<T>`)
299 // 1) we have no aliasing, since we're holding unique reference to `Self`, and
300 // 2) `this.inner` is not deallocated for the duration of this method
301 let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
302 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = inner.pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values..poprust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]pop().() {
303 return Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value));
304 }
305 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().inner.pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers..is_emptyrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]is_empty().() {
306 for waker in inner.pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers..drainrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]drain().(..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#) {
307 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().waker.will_wakerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker]will_wake().(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().()) {
308 waker.wakerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker]wake().();
309 }
310 }
311 }
312 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stream_waker) = inner.stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() {
313 stream_waker.clone_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker][Clone]clone_from().(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().());
314 } else {
315 inner.stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker][Clone]clone().());
316 }
317
318 // SAFETY: ensure that we're not holding a reference to this.inner
319 _ = inner;
320
321 // SAFETY for Inner<T>:
322 // - `ACTIVE_STREAM_INNER` now contains valid pointer to `this.inner` during the call to `fut.poll`
323 // - `ACTIVE_STREAM_INNER` is restored after the call due to the use of guard
324 let polling_ptr_guard =
325 ActiveStreamPointerGuardrust-analyzer cargo async-fn-stream 0.3.2 ActiveStreamPointerGuard#::set_active_ptrrust-analyzer cargo async-fn-stream 0.3.2 impl#[ActiveStreamPointerGuard]set_active_ptr().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::as_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`]as_ptr().(&*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner.).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().());
326 let r = this.futrust-analyzer cargo async-fn-stream 0.3.2 Projection#fut..pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().(cx);
327 droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().(polling_ptr_guard);
328
329 // SAFETY:
330 // (see safety comment for `Inner<T>`)
331 // 1) we have no aliasing, since:
332 // - we're holding unique reference to `Self`, and
333 // - we removed the pointer from `ACTIVE_STREAM_INNER`
334 // 2) `this.inner` is not deallocated for the duration of this method
335 let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
336 match r {
337 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())) => Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
338 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)) => {
339 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().this.is_errrust-analyzer cargo async-fn-stream 0.3.2 Projection#is_err. = true;
340 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)))
341 }
342 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending# => {
343 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = inner.pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values..poprust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]pop().() {
344 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value))
345 } else {
346 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending#
347 }
348 }
349 }
350 }
351 }
352
353 impl<T> StreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#<T> {
354 /// Emit value from a stream and wait until stream consumer calls [`futures_util::StreamExt::next`] again.
355 ///
356 /// # Panics
357 /// Will panic if:
358 /// * `emit` is called not in context of polling the stream
359 #[must_use = "Ensure that emit() is awaited"]
360 pub fn emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(&'_ self, value: T) -> EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, T> {
361 EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#::newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`]new().(&self.innerrust-analyzer cargo async-fn-stream 0.3.2 StreamEmitter#inner., value)
362 }
363 }
364
365 impl<T, E> TryStreamEmitterrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#<T, E> {
366 /// Emit value from a stream and wait until stream consumer calls [`futures_util::StreamExt::next`] again.
367 ///
368 /// # Panics
369 /// Will panic if:
370 /// * `emit` is called not in context of polling the stream
371 #[must_use = "Ensure that emit() is awaited"]
372 pub fn emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(&'_ self, value: T) -> EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>> {
373 EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#::newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`]new().(&self.innerrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#inner., Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value))
374 }
375
376 /// Emit value from a stream and wait until stream consumer calls [`futures_util::StreamExt::next`] again.
377 ///
378 /// # Panics
379 /// Will panic if:
380 /// * `emit_result` is called not in context of polling the stream
381 #[must_use = "Ensure that emit() is awaited"]
382 pub fn emit_resultrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit_result().(&'_ self, value: Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>) -> EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>> {
383 EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#::newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`]new().(&self.innerrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#inner., value)
384 }
385
386 /// Emit error from a stream and wait until stream consumer calls [`futures_util::StreamExt::next`] again.
387 ///
388 /// # Panics
389 /// Will panic if:
390 /// * `emit_err` is called not in context of polling the stream
391 #[must_use = "Ensure that emit_err() is awaited"]
392 pub fn emit_errrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit_err().(&'_ self, err: E) -> EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>> {
393 EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#::newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`]new().(&self.innerrust-analyzer cargo async-fn-stream 0.3.2 TryStreamEmitter#inner., Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err))
394 }
395 }
396
397 pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!! {
398 /// Future returned from [`StreamEmitter::emit`].
399 pub struct EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'a, T> {
400 innerrust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#inner.: &'a UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<T>>,
401 valuerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#value.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T>,
402 }
403 }
404
405 impl<'a, T> EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'a, T> {
406 fn newrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`]new().(inner: &'a UnsafeCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/UnsafeCell#<Innerrust-analyzer cargo async-fn-stream 0.3.2 Inner#<T>>, value: T) -> Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`] {
407 Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`] {
408 innerrust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#inner.,
409 valuerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#value.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value),
410 }
411 }
412 }
413
414 impl<T> Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# for EmitFuturerust-analyzer cargo async-fn-stream 0.3.2 EmitFuture#<'_, T> {
415 type Outputrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'_, T>`][Future]Output# = ();
416
417 fn pollrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'_, T>`][Future]poll().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'_, T>`][Future]>, cx: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::taskrust-analyzer cargo std https://github.com/rust-lang/rust/library/std task/::Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#<'_>) -> Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#<Selfrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'_, T>`][Future]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#> {
418 let this = self.projectrust-analyzer cargo async-fn-stream 0.3.2 impl#[`EmitFuture<'a, T>`]project().();
419 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
420 ACTIVE_STREAM_INNERrust-analyzer cargo async-fn-stream 0.3.2 ACTIVE_STREAM_INNER..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/local/impl#[`LocalKey<Cell<T>>`]get().() == stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::from_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/from_ref().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner.).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().::<()>(),
421 "StreamEmitter::emit().await should only be called in the context of the corresponding `fn_stream()`/`try_fn_stream()`"
422 );
423 // SAFETY:
424 // 1) we hold a unique reference to `this.inner` since we verified that ACTIVE_STREAM_INNER == self.inner
425 // - we're calling `{Try,}FnStream::poll_next` in this thread, which holds the only other reference to the same instance of `Inner<T>`
426 // - `{Try,}FnStream::poll_next` is not holding a reference to `self.inner` during the call to `fut.poll`
427 // 2) `this.inner` is not deallocated for the duration of this method
428 let inner = unsafe { &mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().this.innerrust-analyzer cargo async-fn-stream 0.3.2 Projection#inner..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/impl#[`UnsafeCell<T>`]get().() };
429
430 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) = this.valuerust-analyzer cargo async-fn-stream 0.3.2 Projection#value..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() {
431 inner.pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values..pushrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]push().(value);
432 let is_same_waker = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stream_waker) = inner.stream_wakerrust-analyzer cargo async-fn-stream 0.3.2 Inner#stream_waker..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().() {
433 stream_waker.will_wakerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker]will_wake().(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().())
434 } else {
435 false
436 };
437 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_same_waker {
438 inner.pending_wakersrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_wakers..pushrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]push().(cx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().().clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker][Clone]clone().());
439 }
440 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending#
441 } else if inner.pending_valuesrust-analyzer cargo async-fn-stream 0.3.2 Inner#pending_values..is_emptyrust-analyzer cargo smallvec 1.15.2 impl#[`SmallVec<A>`]is_empty().() {
442 // stream only polls the future after draining `inner.pending_values`, so this check should not be necessary in theory;
443 // this is just a safeguard against misuses; e.g. if a future calls `.emit().poll()` in a loop without yielding on `Poll::Pending`,
444 // this would lead to overflow of `inner.pending_values`
445 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(())
446 } else {
447 Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Pendingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Pending#
448 }
449 }
450 }
451
452 #[cfg(test)]
453 mod testsrust-analyzer cargo async-fn-stream 0.3.2 tests/ {
454 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#, pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!};
455
456 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-util 0.3.34 stream/::FuturesUnorderedrust-analyzer cargo futures-util 0.3.34 stream/futures_unordered/FuturesUnordered#, StreamExtrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#};
457
458 use superrust-analyzer cargo async-fn-stream 0.3.2 crate/::*;
459
460 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
461 fn infallible_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/infallible_works().() {
462 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
463 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
464 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("stream 1");
465 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(1).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().;
466 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("stream 2");
467 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(2).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().;
468 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("stream 3");
469 });
470 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
471 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), 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().);
472 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2), 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().);
473 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
474 });
475 }
476
477 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
478 fn infallible_lifetimerust-analyzer cargo async-fn-stream 0.3.2 tests/infallible_lifetime().() {
479 let a = 1;
480 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
481 let b = 2;
482 let a = &a;
483 let b = &b;
484 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
485 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("stream 1");
486 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(a).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().;
487 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("stream 2");
488 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(b).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().;
489 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("stream 3");
490 });
491 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
492 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(a), 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().);
493 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(b), 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().);
494 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
495 });
496 }
497
498 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
499 fn infallible_unawaited_emit_is_ignoredrust-analyzer cargo async-fn-stream 0.3.2 tests/infallible_unawaited_emit_is_ignored().() {
500 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
501 #[expect(
502 unused_must_use,
503 reason = "this code intentionally does not await emitter.emit()"
504 )]
505 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
506 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(1)/* .await */;
507 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(2)/* .await */;
508 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(3).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().;
509 });
510 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
511 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(3), 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().);
512 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
513 });
514 }
515
516 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
517 fn fallible_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/fallible_works().() {
518 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
519 let stream = try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().(|emitter| async move {
520 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 1");
521 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(1).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().;
522 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 2");
523 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(2).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().;
524 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 3");
525 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#))
526 });
527 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
528 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, 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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
529 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(2, 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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
530 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
531 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
532 });
533 }
534
535 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
536 fn fallible_emit_err_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/fallible_emit_err_works().() {
537 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
538 let stream = try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().(|emitter| async move {
539 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 1");
540 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(1).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().;
541 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 2");
542 emitter.emit_resultrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit_result().(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(2)).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().;
543 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 3");
544 emitter
545 .emit_errrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit_err().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#))
546 .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().;
547 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 4");
548 emitter
549 .emit_resultrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit_result().(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#)))
550 .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().;
551 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 5");
552 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][`From<ErrorKind>`]from().(ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#))
553 });
554 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
555 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, 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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
556 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(2, 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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
557 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
558 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
559 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
560 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(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()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
561 });
562 }
563
564 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
565 fn method_asyncrust-analyzer cargo async-fn-stream 0.3.2 tests/method_async().() {
566 struct Strust-analyzer cargo async-fn-stream 0.3.2 tests/St# {
567 arust-analyzer cargo async-fn-stream 0.3.2 tests/St#a.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
568 }
569
570 impl Strust-analyzer cargo async-fn-stream 0.3.2 tests/St# {
571 async fn f1rust-analyzer cargo async-fn-stream 0.3.2 tests/impl#[St]f1().(&self) -> impl Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream#<Itemrust-analyzer cargo futures-core 0.3.34 stream/Stream#Item# = &str> {
572 self.f2rust-analyzer cargo async-fn-stream 0.3.2 tests/impl#[St]f2().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
573 }
574
575 #[allow(clippy::unused_async)]
576 async fn f2rust-analyzer cargo async-fn-stream 0.3.2 tests/impl#[St]f2().(&self) -> impl Streamrust-analyzer cargo futures-core 0.3.34 stream/Stream#<Itemrust-analyzer cargo futures-core 0.3.34 stream/Stream#Item# = &str> {
577 fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
578 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(self.arust-analyzer cargo async-fn-stream 0.3.2 tests/St#a..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).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().;
579 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(self.arust-analyzer cargo async-fn-stream 0.3.2 tests/St#a..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).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().;
580 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(self.arust-analyzer cargo async-fn-stream 0.3.2 tests/St#a..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()).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().;
581 })
582 }
583 }
584
585 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
586 let l = Strust-analyzer cargo async-fn-stream 0.3.2 tests/St# {
587 arust-analyzer cargo async-fn-stream 0.3.2 tests/St#a.: "qwe".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
588 };
589 let s = l.f1rust-analyzer cargo async-fn-stream 0.3.2 tests/impl#[St]f1().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
590 let z: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = s.collectrust-analyzer cargo futures-util 0.3.34 stream/stream/StreamExt#collect().().rust-analyzer cargo futures-util 0.3.34 stream/stream/collect/impl#[`Collect<St, C>`][Future]poll().awaitrust-analyzer cargo futures-util 0.3.34 stream/stream/collect/impl#[`Collect<St, C>`][Future]poll().;
591 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(z, ["qwe", "qwe", "qwe"]);
592 });
593 }
594
595 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
596 fn tokio_join_one_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/tokio_join_one_works().() {
597 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
598 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
599 tokiorust-analyzer cargo tokio 1.53.1 crate/::joinrust-analyzer cargo tokio 1.53.1 macros/join/join!!(async { emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(1).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(). },);
600 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(2).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().;
601 });
602 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
603 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), 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().);
604 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2), 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().);
605 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
606 });
607 }
608
609 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
610 fn tokio_join_many_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/tokio_join_many_works().() {
611 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
612 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
613 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("try stream 1");
614 tokiorust-analyzer cargo tokio 1.53.1 crate/::joinrust-analyzer cargo tokio 1.53.1 macros/join/join!!(
615 async { emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(1).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(). },
616 async { emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(2).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(). },
617 async { emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(3).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(). },
618 );
619 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(4).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().;
620 });
621 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
622 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#3 {
623 let item = 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().;
624 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(item, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1..=3)));
625 }
626 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4), 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().);
627 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
628 });
629 }
630
631 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
632 fn tokio_futures_unordered_one_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/tokio_futures_unordered_one_works().() {
633 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
634 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
635 let mut futs: FuturesUnorderedrust-analyzer cargo futures-util 0.3.34 stream/futures_unordered/FuturesUnordered#<_> = (1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#1)
636 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| {
637 let emitter = &emitter;
638 async move { 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(). }
639 })
640 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
641 while futs.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()..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {}
642 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(2).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().;
643 });
644 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
645 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1), 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().);
646 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(2), 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().);
647 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
648 });
649 }
650
651 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
652 fn tokio_futures_unordered_many_worksrust-analyzer cargo async-fn-stream 0.3.2 tests/tokio_futures_unordered_many_works().() {
653 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
654 let stream = fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
655 let mut futs: FuturesUnorderedrust-analyzer cargo futures-util 0.3.34 stream/futures_unordered/FuturesUnordered#<_> = (1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#3)
656 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|i| {
657 let emitter = &emitter;
658 async move { 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(). }
659 })
660 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
661 while futs.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()..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {}
662 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(4).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().;
663 });
664 pin_mutrust-analyzer cargo futures-util 0.3.34 macros/pin_mut!!(stream);
665 for _ in 1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#3 {
666 let item = 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().;
667 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(item, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1..=3)));
668 }
669 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(4), 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().);
670 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, 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().);
671 });
672 }
673
674 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
675 fn infallible_nested_streams_workrust-analyzer cargo async-fn-stream 0.3.2 tests/infallible_nested_streams_work().() {
676 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
677 let mut stream = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
678 for i in 0..3 {
679 let mut stream_2 = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
680 for j in 0..3 {
681 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(j).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().;
682 }
683 }));
684 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = stream_2.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(). {
685 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(3 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). item).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().;
686 }
687 }
688 }));
689 let mut sum = 0;
690 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = 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(). {
691 sum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().item;
692 }
693 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, 36);
694 });
695 }
696
697 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
698 fn fallible_nested_streams_workrust-analyzer cargo async-fn-stream 0.3.2 tests/fallible_nested_streams_work().() {
699 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
700 let mut stream = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().(|emitter| async move {
701 for i in 0..3 {
702 let mut stream_2 = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().(|emitter| async move {
703 for j in 0..3 {
704 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(j).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().;
705 }
706 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>(())
707 }));
708 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(item)) = stream_2.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(). {
709 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(3 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). item).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().;
710 }
711 }
712 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>(())
713 }));
714 let mut sum = 0;
715 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(item)) = 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(). {
716 sum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().item;
717 }
718 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, 36);
719 });
720 }
721
722 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
723 #[should_panic(
724 expected = "StreamEmitter::emit().await should only be called in the context of the corresponding `fn_stream()`/`try_fn_stream()`"
725 )]
726 fn infallible_bad_nested_emit_detectedrust-analyzer cargo async-fn-stream 0.3.2 tests/infallible_bad_nested_emit_detected().() {
727 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
728 let mut stream = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter| async move {
729 for i in 0..3 {
730 let emitter_ref = &emitter;
731 let mut stream_2 = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(fn_streamrust-analyzer cargo async-fn-stream 0.3.2 fn_stream().(|emitter_2| async move {
732 emitter_2.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(0).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().;
733 for j in 0..3 {
734 emitter_ref.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(j).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().;
735 }
736 }));
737 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = stream_2.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(). {
738 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`StreamEmitter<T>`]emit().(3 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). item).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().;
739 }
740 }
741 }));
742
743 let mut sum = 0;
744 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item) = 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(). {
745 sum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().item;
746 }
747 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, 36);
748 });
749 }
750
751 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
752 #[should_panic(
753 expected = "StreamEmitter::emit().await should only be called in the context of the corresponding `fn_stream()`/`try_fn_stream()`"
754 )]
755 fn fallible_bad_nested_emit_detectedrust-analyzer cargo async-fn-stream 0.3.2 tests/fallible_bad_nested_emit_detected().() {
756 futures_executorrust-analyzer cargo futures-executor 0.3.34 crate/::block_onrust-analyzer cargo futures-executor 0.3.34 local_pool/block_on().(async {
757 let mut stream = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().(|emitter| async move {
758 for i in 0..3 {
759 let emitter_ref = &emitter;
760 let mut stream_2 = pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/pin!!(try_fn_streamrust-analyzer cargo async-fn-stream 0.3.2 try_fn_stream().(|emitter_2| async move {
761 emitter_2.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(0).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().;
762 for j in 0..3 {
763 emitter_ref.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(j).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().;
764 }
765 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>(())
766 }));
767 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(item)) = stream_2.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(). {
768 emitter.emitrust-analyzer cargo async-fn-stream 0.3.2 impl#[`TryStreamEmitter<T, E>`]emit().(3 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). item).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().;
769 }
770 }
771 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#::<_, ()>(())
772 }));
773
774 let mut sum = 0;
775 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(item)) = 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(). {
776 sum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().item;
777 }
778 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(sum, 36);
779 });
780 }
781 }