[][src]Trait futures_core::stream::Stream

#[must_use = "streams do nothing unless polled"]
pub trait Stream {
    type Item;
    fn poll_next(
        self: Pin<&mut Self>,
        cx: &mut Context
    ) -> Poll<Option<Self::Item>>; }

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.

Loading content...

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 subsequent poll_next calls.

  • Poll::Ready(None) means that the stream has terminated, and poll_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.

Loading content...

Implementations on Foreign Types

impl<'_, S: ?Sized + Stream + Unpin> Stream for &'_ mut S[src]

type Item = S::Item

impl<P> Stream for Pin<P> where
    P: DerefMut + Unpin,
    P::Target: Stream
[src]

type Item = <P::Target as Stream>::Item

impl<S: ?Sized + Stream + Unpin> Stream for Box<S>[src]

type Item = S::Item

impl<S: Stream> Stream for AssertUnwindSafe<S>[src]

type Item = S::Item

impl<T: Unpin> Stream for VecDeque<T>[src]

type Item = T

Loading content...

Implementors

Loading content...