pub trait StreamExt {
// Required methods
fn chain_ready<T>(self, item: T) -> Chain<Self, Once<Ready<T>>>
where Self: Sized + Stream<Item = T>;
fn chain_future<T, F>(self, fut: F) -> Chain<Self, Once<F>>
where Self: Sized + Stream<Item = T>,
F: Future<Output = T>;
}Available on crate feature
stream only.Expand description
futures::Stream extensions.
Required Methods§
Sourcefn chain_ready<T>(self, item: T) -> Chain<Self, Once<Ready<T>>>
fn chain_ready<T>(self, item: T) -> Chain<Self, Once<Ready<T>>>
Chains a single ready item to the end of the stream.
This method appends a ready item to the stream, effectively increasing the length of the stream by one. The item will be yielded after all items from the original stream.
§Examples
let initial_stream = futures::stream::iter(vec![1, 2, 3]);
let chained_stream = initial_stream.chain_ready(4);
let collected: Vec<_> = futures::executor::block_on_stream(chained_stream).collect();
assert_eq!(collected, vec![1, 2, 3, 4]);Sourcefn chain_future<T, F>(self, fut: F) -> Chain<Self, Once<F>>
fn chain_future<T, F>(self, fut: F) -> Chain<Self, Once<F>>
Chains a single future to the end of the stream.
This method appends a future to the stream. When polled, the future will be awaited, and its resulting item will be yielded after all items from the original stream.
§Examples
let initial_stream = futures::stream::iter(vec![1, 2, 3]);
let chained_stream = initial_stream.chain_future(Box::pin(async { 4 }));
let collected: Vec<_> = futures::executor::block_on_stream(chained_stream).collect();
assert_eq!(collected, vec![1, 2, 3, 4]);