Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! A very small, no-std compatible toolbox of async utilities.
2 #![no_std]
3 #![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
4
5 pub mod preluderust-analyzer cargo futures-micro 1.0.0-rc0 prelude/;
6
7 #[doc(no_inline)]
8 pub use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#;
9 #[doc(no_inline)]
10 pub use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::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#;
11 #[doc(no_inline)]
12 pub use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::taskrust-analyzer cargo core https://github.com/rust-lang/rust/library/core 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#, Wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Waker#};
13
14 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/;
15
16 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!;
17
18 // ---------- futures using the poll api -----------
19
20 /// Creates a future from a function returning [`Poll`].
21 ///
22 /// # Examples
23 ///
24 /// ```
25 /// use futures_lite::future::block_on;
26 /// use futures_micro::poll_fn;
27 /// use std::task::{Context, Poll};
28 ///
29 /// # block_on(async {
30 /// fn f(_ctx: &mut Context<'_>) -> Poll<i32> {
31 /// Poll::Ready(7)
32 /// }
33 ///
34 /// assert_eq!(poll_fn(f).await, 7);
35 /// # })
36 /// ```
37 #[inline(always)]
38 pub fn poll_fnrust-analyzer cargo futures-micro 1.0.0-rc0 poll_fn().<F, T>(inner: F) -> PollFnrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn#<F>
39 where
40 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut 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#<T>,
41 {
42 PollFnrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn# { innerrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn#inner. }
43 }
44
45 pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!! {
46 /// Future for the [`poll_fn()`] function.
47 #[must_use = "futures do nothing unless you `.await` or poll them"]
48 pub struct PollFnrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn#<F> {
49 innerrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn#inner.: F,
50 }
51 }
52
53 impl<F> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for PollFnrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn#<F> {
54 fn fmtrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`PollFn<F>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
55 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("PollFn").finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
56 }
57 }
58
59 impl<F, T> Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# for PollFnrust-analyzer cargo futures-micro 1.0.0-rc0 PollFn#<F>
60 where
61 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&mut 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#<T>,
62 {
63 type Outputrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`PollFn<F>`][Future]Output# = T;
64 fn pollrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`PollFn<F>`][Future]poll().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`PollFn<F>`][Future]>, ctx: &mut 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#<T> {
65 let this = self.projectrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`PollFn<F>`]project().();
66 (this.innerrust-analyzer cargo futures-micro 1.0.0-rc0 Projection#inner.)(ctx)
67 }
68 }
69
70 pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!! {
71 /// Returns the result of `left` or `right` future, preferring `left` if both are ready.
72 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
73 #[must_use = "futures do nothing unless you `.await` or poll them"]
74 pub struct Orrust-analyzer cargo futures-micro 1.0.0-rc0 Or#<F1, F2> {
75 #[pin]
76 future1rust-analyzer cargo futures-micro 1.0.0-rc0 Or#future1.: F1,
77 #[pin]
78 future2rust-analyzer cargo futures-micro 1.0.0-rc0 Or#future2.: F2,
79 }
80 }
81
82 impl<F1, F2> Orrust-analyzer cargo futures-micro 1.0.0-rc0 Or#<F1, F2>
83 where
84 F1: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
85 F2: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
86 {
87 /// Returns the result of `left` or `right` future, preferring `left` if both are ready.
88 pub fn newrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`]new().(future1: F1, future2: F2) -> Selfrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`] {
89 Orrust-analyzer cargo futures-micro 1.0.0-rc0 Or# { future1rust-analyzer cargo futures-micro 1.0.0-rc0 Or#future1., future2rust-analyzer cargo futures-micro 1.0.0-rc0 Or#future2. }
90 }
91 }
92
93 impl<T, F1, F2> Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# for Orrust-analyzer cargo futures-micro 1.0.0-rc0 Or#<F1, F2>
94 where
95 F1: 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# = T>,
96 F2: 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# = T>,
97 {
98 type Outputrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`][Future]Output# = T;
99
100 fn pollrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`][Future]poll().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`][Future]>, cx: &mut 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 futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`][Future]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#> {
101 let this = self.projectrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Or<F1, F2>`]project().();
102
103 if let 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#(t) = this.future1rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#future1..pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().(cx) {
104 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#(t)
105 } else if let 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#(t) = this.future2rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#future2..pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().(cx) {
106 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#(t)
107 } else {
108 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#
109 }
110 }
111 }
112
113 pin_projectrust-analyzer cargo pin-project-lite 0.2.17 pin_project!! {
114 /// Waits for two [`Future`]s to complete, returning both results.
115 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
116 #[must_use = "futures do nothing unless you `.await` or poll them"]
117 pub struct Ziprust-analyzer cargo futures-micro 1.0.0-rc0 Zip#<F1, F2>
118 where
119 F1: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
120 F2: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
121 {
122 #[pin]
123 future1rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#future1.: F1,
124 output1rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#output1.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<F1::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#>,
125 #[pin]
126 future2rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#future2.: F2,
127 output2rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#output2.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<F2::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#>,
128 }
129 }
130
131 impl<F1, F2> Ziprust-analyzer cargo futures-micro 1.0.0-rc0 Zip#<F1, F2>
132 where
133 F1: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
134 F2: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
135 {
136 /// Zips two futures, waiting for both to complete.
137 ///
138 /// # Examples
139 ///
140 /// ```
141 /// use futures_micro::Zip;
142 ///
143 /// # futures_lite::future::block_on(async {
144 /// let a = async { 1 };
145 /// let b = async { 2 };
146 ///
147 /// assert_eq!(Zip::new(a, b).await, (1, 2));
148 /// # })
149 /// ```
150 pub fn newrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`]new().(future1: F1, future2: F2) -> Selfrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`] {
151 Ziprust-analyzer cargo futures-micro 1.0.0-rc0 Zip# {
152 future1rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#future1.,
153 future2rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#future2.,
154 output1rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#output1.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
155 output2rust-analyzer cargo futures-micro 1.0.0-rc0 Zip#output2.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
156 }
157 }
158 }
159
160 impl<F1, F2> Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future# for Ziprust-analyzer cargo futures-micro 1.0.0-rc0 Zip#<F1, F2>
161 where
162 F1: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
163 F2: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#,
164 {
165 type Outputrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`][Future]Output# = (F1::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#, F2::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#);
166
167 fn pollrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`][Future]poll().(self: Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#<&mut Selfrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`][Future]>, cx: &mut 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 futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`][Future]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output#> {
168 let this = self.projectrust-analyzer cargo futures-micro 1.0.0-rc0 impl#[`Zip<F1, F2>`]project().();
169
170 if this.output1rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output1..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
171 if let 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#(out) = this.future1rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#future1..pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().(cx) {
172 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().this.output1rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output1. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(out);
173 }
174 }
175
176 if this.output2rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output2..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
177 if let 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#(out) = this.future2rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#future2..pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().(cx) {
178 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().this.output2rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output2. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(out);
179 }
180 }
181
182 if this.output1rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output1..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() && this.output2rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output2..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
183 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#((this.output1rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output1..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(), this.output2rust-analyzer cargo futures-micro 1.0.0-rc0 Projection#output2..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()))
184 } else {
185 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#
186 }
187 }
188 }
189
190 /// Get the [`Waker`] inside an async fn where you aren't supposed to
191 /// have it.
192 ///
193 /// This is a low level primitive for implementing more complex
194 /// patterns while avoiding the [`Poll`] API.
195 ///
196 /// # Examples
197 ///
198 /// ```
199 /// use futures_micro::{sleep, waker};
200 ///
201 /// # futures_lite::future::block_on(async {
202 /// let waker = waker().await;
203 /// assert_eq!(async { waker.wake(); sleep().await; 1 }.await, 1)
204 /// # })
205 /// ```
206 pub fn wakerrust-analyzer cargo futures-micro 1.0.0-rc0 waker().() -> impl 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# = Wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Waker#> {
207 poll_fnrust-analyzer cargo futures-micro 1.0.0-rc0 poll_fn().(|ctx| 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#(ctx.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().()))
208 }
209
210 /// Goes to sleep until woken by its [`Waker`] being called.
211 ///
212 /// This is a low level primitive for implementing more complex
213 /// patterns while avoiding the [`Poll`] API.
214 ///
215 /// # Examples
216 ///
217 /// ```
218 /// use futures_micro::{sleep, waker};
219 ///
220 /// # futures_lite::future::block_on(async {
221 /// let waker = waker().await;
222 /// assert_eq!(async { waker.wake(); sleep().await; 1 }.await, 1)
223 /// # })
224 /// ```
225 pub fn sleeprust-analyzer cargo futures-micro 1.0.0-rc0 sleep().() -> impl 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# = ()> {
226 let mut done = false;
227 poll_fnrust-analyzer cargo futures-micro 1.0.0-rc0 poll_fn().(move |_| {
228 if done {
229 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#(())
230 } else {
231 done = true;
232 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#
233 }
234 })
235 }
236
237 /// Pushes itself to the back of the executor queue so some other
238 /// tasks can do some work.
239 pub fn yield_oncerust-analyzer cargo futures-micro 1.0.0-rc0 yield_once().() -> impl 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# = ()> {
240 let mut done = false;
241 poll_fnrust-analyzer cargo futures-micro 1.0.0-rc0 poll_fn().(move |ctx| {
242 if done {
243 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#(())
244 } else {
245 done = true;
246 ctx.wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]waker().().wake_by_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[Waker]wake_by_ref().();
247 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#
248 }
249 })
250 }
251
252 // --------- MACROS ---------
253
254 // Helper for `or!`
255 #[doc(hidden)]
256 #[macro_export]
257 macro_rules! __internal_fold_withrust-analyzer cargo futures-micro 1.0.0-rc0 __internal_fold_with! {
258 ($func:path, $e:expr) => { $e };
259 ($func:path, $e:expr, $($es:expr),+) => {
260 $func($e, $crate::__internal_fold_with!($func, $($es),+))
261 };
262 }
263
264 /// Polls arbitrarily many futures, returning the first ready value.
265 ///
266 /// All futures must have the same output type. Left biased when more
267 /// than one Future is ready at the same time.
268 #[macro_export]
269 macro_rules! orrust-analyzer cargo futures-micro 1.0.0-rc0 or! {
270 ($($es:expr),+$(,)?) => { $crate::__internal_fold_with!($crate::Or::new, $($es),+) };
271 }
272
273 /// Pins a variable of type `T` on the stack and rebinds it as `Pin<&mut T>`.
274 ///
275 /// ```
276 /// use futures_micro::*;
277 /// use std::fmt::Debug;
278 /// use std::time::Instant;
279 ///
280 /// // Inspects each invocation of `Future::poll()`.
281 /// async fn inspect<T: Debug>(f: impl Future<Output = T>) -> T {
282 /// pin!(f);
283 /// poll_fn(|cx| dbg!(f.as_mut().poll(cx))).await
284 /// }
285 ///
286 /// # futures_lite::future::block_on(async {
287 /// let f = async { 1 + 2 };
288 /// inspect(f).await;
289 /// # })
290 /// ```
291 #[macro_export]
292 macro_rules! pinrust-analyzer cargo futures-micro 1.0.0-rc0 pin! {
293 ($($x:ident),* $(,)?) => {
294 $(
295 let mut $x = $x;
296 #[allow(unused_mut)]
297 let mut $x = unsafe {
298 core::pin::Pin::new_unchecked(&mut $x)
299 };
300 )*
301 }
302 }
303
304 /// Unwraps `Poll<T>` or returns [`Pending`][`Poll::Pending`].
305 ///
306 /// # Examples
307 ///
308 /// ```
309 /// use futures_micro::*;
310 ///
311 /// // Polls two futures and sums their results.
312 /// fn poll_sum(
313 /// cx: &mut Context<'_>,
314 /// mut a: impl Future<Output = i32> + Unpin,
315 /// mut b: impl Future<Output = i32> + Unpin,
316 /// ) -> Poll<i32> {
317 /// let x = ready!(Pin::new(&mut a).poll(cx));
318 /// let y = ready!(Pin::new(&mut b).poll(cx));
319 /// Poll::Ready(x + y)
320 /// }
321 /// ```
322 #[macro_export]
323 macro_rules! readyrust-analyzer cargo futures-micro 1.0.0-rc0 ready! {
324 ($e:expr $(,)?) => {
325 match $e {
326 core::task::Poll::Ready(t) => t,
327 t @ core::task::Poll::Pending => return t,
328 }
329 };
330 }
331
332 /// Zips arbitrarily many futures, waiting for all to complete.
333 ///
334 /// # Examples
335 ///
336 /// ```
337 /// use futures_micro::zip;
338 ///
339 /// # futures_lite::future::block_on(async {
340 /// let a = async { 1 };
341 /// let b = async { 2 };
342 ///
343 /// assert_eq!(zip!(a, b).await, (1, 2));
344 /// # })
345 /// ```
346 #[macro_export]
347 macro_rules! ziprust-analyzer cargo futures-micro 1.0.0-rc0 zip! {
348 ($($es:expr),+ $(,)?) => {{
349 let mut zips = $crate::__internal_fold_with!($crate::Zip::new, $($es),+);
350 $crate::poll_fn(move |ctx| {
351 use ::core::pin::Pin;
352 use ::core::task::Poll;
353
354 let zips = unsafe { Pin::new_unchecked(&mut zips) };
355 if let Poll::Ready(val) = ::core::future::Future::poll(zips, ctx) {
356 Poll::Ready($crate::zip!(@flatten; ; val; $($es),+))
357 } else {
358 Poll::Pending
359 }
360 })
361 }};
362
363 (@flatten; $($prev:expr,)*; $tuple:expr; $e:expr) => {
364 ($($prev,)* $tuple)
365 };
366
367 (@flatten; $($prev:expr,)*; $tuple:expr; $e:expr, $($es:expr),+) => {
368 $crate::zip!(@flatten; $($prev,)* $tuple.0,; $tuple.1; $($es),+)
369 };
370 }