pub trait StreamExt: Stream {
// Required methods
fn merge<T, S2>(
self,
other: S2,
) -> Merge2<T, Self, <S2 as IntoStream>::IntoStream>
where Self: Sized + Stream<Item = T>,
S2: IntoStream<Item = T>;
fn chain<T, S2>(
self,
other: S2,
) -> Chain2<Self, <S2 as IntoStream>::IntoStream>
where Self: Sized + Stream<Item = T>,
S2: IntoStream<Item = T>;
fn zip<T, S2>(self, other: S2) -> Zip2<Self, <S2 as IntoStream>::IntoStream>
where Self: Sized + Stream<Item = T>,
S2: IntoStream<Item = T>;
// Provided methods
fn co(self) -> FromStream<Self>
where Self: Sized { ... }
fn wait_until<D>(
self,
deadline: D,
) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>
where Self: Sized,
D: IntoFuture { ... }
}Available on crate feature
nano-alloc only.Expand description
An extension trait for the Stream trait.
Required Methods§
Sourcefn merge<T, S2>(
self,
other: S2,
) -> Merge2<T, Self, <S2 as IntoStream>::IntoStream>
fn merge<T, S2>( self, other: S2, ) -> Merge2<T, Self, <S2 as IntoStream>::IntoStream>
Combines two streams into a single stream of all their outputs.
Sourcefn chain<T, S2>(self, other: S2) -> Chain2<Self, <S2 as IntoStream>::IntoStream>
fn chain<T, S2>(self, other: S2) -> Chain2<Self, <S2 as IntoStream>::IntoStream>
Takes two streams and creates a new stream over all in sequence
Sourcefn zip<T, S2>(self, other: S2) -> Zip2<Self, <S2 as IntoStream>::IntoStream>
fn zip<T, S2>(self, other: S2) -> Zip2<Self, <S2 as IntoStream>::IntoStream>
‘Zips up’ multiple streams into a single stream of pairs.
Provided Methods§
Sourcefn co(self) -> FromStream<Self>where
Self: Sized,
Available on crate feature alloc only.
fn co(self) -> FromStream<Self>where
Self: Sized,
alloc only.Convert into a concurrent stream.
Sourcefn wait_until<D>(
self,
deadline: D,
) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>where
Self: Sized,
D: IntoFuture,
fn wait_until<D>(
self,
deadline: D,
) -> WaitUntil<Self, <D as IntoFuture>::IntoFuture>where
Self: Sized,
D: IntoFuture,
Delay the yielding of items from the stream until the given deadline.
The underlying stream will not be polled until the deadline has expired. In addition to using a time source as a deadline, any future can be used as a deadline too. When used in combination with a multi-consumer channel, this method can be used to synchronize the start of multiple streams and futures.
§Example
use async_io::Timer;
use futures_concurrency::prelude::*;
use futures_lite::{future::block_on, stream};
use futures_lite::prelude::*;
use std::time::{Duration, Instant};
block_on(async {
let now = Instant::now();
let duration = Duration::from_millis(100);
stream::once("meow")
.wait_until(Timer::after(duration))
.next()
.await;
assert!(now.elapsed() >= duration);
});