pub trait Stream {
type Item;
// Required method
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>>;
// Provided method
fn size_hint(&self) -> (usize, Option<usize>) { ... }
}Expand description
Asynchronous iterator producing a sequence of values.
This is the async equivalent of Iterator. Each call to poll_next
attempts to pull out the next value, returning Poll::Pending if the
value is not yet ready, Poll::Ready(Some(item)) if a value is available,
or Poll::Ready(None) if the stream has terminated.
§Examples
ⓘ
use asupersync::stream::{Stream, StreamExt};
async fn process<S: Stream<Item = i32> + Unpin>(mut stream: S) {
while let Some(item) = stream.next().await {
println!("got: {}", item);
}
}Required Associated Types§
Required Methods§
Sourcefn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>>
fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>
Attempt to pull out the next value of this stream.
§Return value
Poll::Pendingmeans the next value is not ready yet.Poll::Ready(Some(val))meansvalis ready and the stream may have more.Poll::Ready(None)means the stream has terminated.
§Cancel Safety
This method is cancel-safe. If poll_next returns Poll::Pending,
no data has been lost.