Sha256: 6e4d2d580189f7d3b6b294b6b17437e8e2570502f08c11786a71caac207f0309
Contents?: true
Size: 1.39 KB
Versions: 27
Compression:
Stored size: 1.39 KB
Contents
use core::mem; use core::pin::Pin; use futures_core::future::{FusedFuture, Future}; use futures_core::ready; use futures_core::stream::{FusedStream, Stream}; use futures_core::task::{Context, Poll}; use pin_project_lite::pin_project; pin_project! { /// Future for the [`collect`](super::StreamExt::collect) method. #[derive(Debug)] #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct Collect<St, C> { #[pin] stream: St, collection: C, } } impl<St: Stream, C: Default> Collect<St, C> { fn finish(self: Pin<&mut Self>) -> C { mem::take(self.project().collection) } pub(super) fn new(stream: St) -> Self { Self { stream, collection: Default::default() } } } impl<St, C> FusedFuture for Collect<St, C> where St: FusedStream, C: Default + Extend<St::Item>, { fn is_terminated(&self) -> bool { self.stream.is_terminated() } } impl<St, C> Future for Collect<St, C> where St: Stream, C: Default + Extend<St::Item>, { type Output = C; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<C> { let mut this = self.as_mut().project(); loop { match ready!(this.stream.as_mut().poll_next(cx)) { Some(e) => this.collection.extend(Some(e)), None => return Poll::Ready(self.finish()), } } } }
Version data entries
27 entries across 27 versions & 1 rubygems