use core::fmt; use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::Stream; use futures_core::task::{Context, Poll}; use pin_project_lite::pin_project;
pin_project! { /// Future for the [`any`](super::StreamExt::any) method. #[must_use = "futures do nothing unless you `.await` or poll them"] pubstruct Any<St, Fut, F> { #[pin]
stream: St,
f: F,
done: bool, #[pin]
future: Option<Fut>,
}
}
impl<St, Fut, F> Future for Any<St, Fut, F> where
St: Stream,
F: FnMut(St::Item) -> Fut,
Fut: Future<Output = bool>,
{ type Output = bool;
fn poll(self: Pin<&mutSelf>, cx: &mut Context<'_>) -> Poll<bool> { letmut this = self.project();
Poll::Ready(loop { iflet Some(fut) = this.future.as_mut().as_pin_mut() { // we're currently processing a future to produce a new value let res = ready!(fut.poll(cx));
this.future.set(None); if res {
*this.done = true; breaktrue;
} // early exit
} elseif !*this.done { // we're waiting on a new item from the stream match ready!(this.stream.as_mut().poll_next(cx)) {
Some(item) => {
this.future.set(Some((this.f)(item)));
}
None => {
*this.done = true; breakfalse;
}
}
} else {
panic!("Any polled after completion")
}
})
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-10-01)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.