[−][src]Trait futures_lite::stream::StreamExt
Extension trait for Stream
.
Provided methods
fn next(&mut self) -> NextFuture<Self>ⓘImportant traits for NextFuture<'_, T>
impl<'_, T: Stream + Unpin + ?Sized> Future for NextFuture<'_, T> type Output = Option<T::Item>;
where
Self: Unpin,
Important traits for NextFuture<'_, T>
impl<'_, T: Stream + Unpin + ?Sized> Future for NextFuture<'_, T> type Output = Option<T::Item>;
Self: Unpin,
Retrieves the next item in the stream.
Returns None
when iteration is finished. Stream implementations may choose to or not to
resume iteration after that.
Examples
use futures_lite::*; let mut s = stream::iter(1..=3); assert_eq!(s.next().await, Some(1)); assert_eq!(s.next().await, Some(2)); assert_eq!(s.next().await, Some(3)); assert_eq!(s.next().await, None);
fn collect<C: Default + Extend<Self::Item>>(self) -> CollectFuture<Self, C>ⓘImportant traits for CollectFuture<St, C>
impl<St, C> Future for CollectFuture<St, C> where
St: Stream,
C: Default + Extend<St::Item>, type Output = C;
where
Self: Sized,
Important traits for CollectFuture<St, C>
impl<St, C> Future for CollectFuture<St, C> where
St: Stream,
C: Default + Extend<St::Item>, type Output = C;
Self: Sized,
Collects all items in the stream into a collection.
Examples
use futures_lite::*; let mut s = stream::iter(1..=3); let items: Vec<_> = s.collect().await; assert_eq!(items, [1, 2, 3]);
fn try_collect<T, C: Default + Extend<T>>(self) -> TryCollectFuture<Self, C>ⓘImportant traits for TryCollectFuture<St, C>
impl<T, E, St, C> Future for TryCollectFuture<St, C> where
St: Stream<Item = Result<T, E>>,
C: Default + Extend<T>, type Output = Result<C, E>;
where
Self: Sized,
Self::Item: Result<Ok = T>,
Important traits for TryCollectFuture<St, C>
impl<T, E, St, C> Future for TryCollectFuture<St, C> where
St: Stream<Item = Result<T, E>>,
C: Default + Extend<T>, type Output = Result<C, E>;
Self: Sized,
Self::Item: Result<Ok = T>,
Collects all items in the fallible stream into a collection.
use futures_lite::*; let s = stream::iter(vec![Ok(1), Err(2), Ok(3)]); let res: Result<Vec<i32>, i32> = s.try_collect().await; assert_eq!(res, Err(2)); let s = stream::iter(vec![Ok(1), Ok(2), Ok(3)]); let res: Result<Vec<i32>, i32> = s.try_collect().await; assert_eq!(res, Ok(vec![1, 2, 3]));