[−][src]Trait futures_core::stream::Stream
A stream of values produced asynchronously.
If Future<Output = T>
is an asynchronous version of T
, then Stream<Item = T>
is an asynchronous version of Iterator<Item = T>
. A stream
represents a sequence of value-producing events that occur asynchronously to
the caller.
The trait is modeled after Future
, but allows poll_next
to be called
even after a value has been produced, yielding None
once the stream has
been fully exhausted.
Associated Types
type Item
Values yielded by the stream.
Required methods
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>>
Attempt to pull out the next value of this stream, registering the
current task for wakeup if the value is not yet available, and returning
None
if the stream is exhausted.
Return value
There are several possible return values, each indicating a distinct stream state:
-
Poll::Pending
means that this stream's next value is not ready yet. Implementations will ensure that the current task will be notified when the next value may be ready. -
Poll::Ready(Some(val))
means that the stream has successfully produced a value,val
, and may produce further values on subsequentpoll_next
calls. -
Poll::Ready(None)
means that the stream has terminated, andpoll_next
should not be invoked again.
Panics
Once a stream is finished, i.e. Ready(None)
has been returned, further
calls to poll_next
may result in a panic or other "bad behavior". If
this is difficult to guard against then the fuse
adapter can be used
to ensure that poll_next
always returns Ready(None)
in subsequent
calls.
Implementations on Foreign Types
impl<'a, S: ?Sized + Stream + Unpin> Stream for &'a mut S
[src]
type Item = S::Item
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>>
[src]
impl<P> Stream for Pin<P> where
P: DerefMut + Unpin,
P::Target: Stream,
[src]
P: DerefMut + Unpin,
P::Target: Stream,
type Item = <P::Target as Stream>::Item
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>>
[src]
impl<A, B> Stream for Either<A, B> where
A: Stream,
B: Stream<Item = A::Item>,
[src]
A: Stream,
B: Stream<Item = A::Item>,
type Item = A::Item
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<A::Item>>
[src]
impl<S: ?Sized + Stream + Unpin> Stream for Box<S>
[src]
type Item = S::Item
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>>
[src]
impl<S: Stream> Stream for AssertUnwindSafe<S>
[src]
type Item = S::Item
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<S::Item>>
[src]
impl<T: Unpin> Stream for VecDeque<T>
[src]
type Item = T
fn poll_next(
self: Pin<&mut Self>,
_cx: &mut Context
) -> Poll<Option<Self::Item>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context
) -> Poll<Option<Self::Item>>