[][src]Trait futures::Stream

pub trait Stream {
    type Item;
    type Error;
    fn poll_next(
        &mut self,
        cx: &mut Context
    ) -> Result<Async<Option<Self::Item>>, Self::Error>; }

A stream of values produced asynchronously.

If Future is an asynchronous version of Result, then Stream is an asynchronous version of Iterator. 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.

Errors

Streams, like futures, also bake in errors through an associated Error type. An error on a stream does not terminate the stream. That is, after one error is received, another value may be received from the same stream (it's valid to keep polling). Thus a stream is somewhat like an Iterator<Item = Result<T, E>>, and is always terminated by returning None.

Associated Types

Values yielded by the stream.

Errors yielded by the stream.

Required Methods

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:

  • Ok(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.

  • Ok(Ready(Some(val))) means that the stream has successfully produced a value, val, and may produce further values on subsequent poll_next calls.

  • Ok(Ready(None)) means that the stream has terminated, and poll_next should not be invoked again.

  • Err(err) means that the stream encountered an error while trying to poll_next. Subsequent calls to poll_next are allowed, and may return further values or errors.

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<S> Stream for Box<S> where
    S: Stream + ?Sized
[src]

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

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

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

impl<A, E, F> Stream for Recover<A, E, F> where
    A: Stream,
    F: FnMut(<A as Stream>::Error) -> Option<<A as Stream>::Item>, 
[src]

Implementors

impl Stream for Never
[src]

impl<A, B> Stream for Either<A, B> where
    A: Stream,
    B: Stream<Item = <A as Stream>::Item, Error = <A as Stream>::Error>, 
[src]

impl<F> Stream for FlattenStream<F> where
    F: Future,
    <F as Future>::Item: Stream,
    <<F as Future>::Item as Stream>::Error == <F as Future>::Error
[src]

impl<F> Stream for IntoStream<F> where
    F: Future
[src]

impl<F> Stream for Once<F> where
    F: Future
[src]

impl<I, E> Stream for IterOk<I, E> where
    I: Iterator
[src]

impl<I, T, E> Stream for IterResult<I> where
    I: Iterator<Item = Result<T, E>>, 
[src]

impl<S> Stream for Buffer<S> where
    S: Sink + Stream
[src]

impl<S> Stream for BufferUnordered<S> where
    S: Stream,
    <S as Stream>::Item: IntoFuture,
    <<S as Stream>::Item as IntoFuture>::Error == <S as Stream>::Error
[src]

impl<S> Stream for Buffered<S> where
    S: Stream,
    <S as Stream>::Item: IntoFuture,
    <<S as Stream>::Item as IntoFuture>::Error == <S as Stream>::Error
[src]

impl<S> Stream for CatchUnwind<S> where
    S: Stream + UnwindSafe
[src]

impl<S> Stream for Chunks<S> where
    S: Stream
[src]

impl<S> Stream for Flatten<S> where
    S: Stream,
    <S as Stream>::Item: Stream,
    <<S as Stream>::Item as Stream>::Error: From<<S as Stream>::Error>, 
[src]

impl<S> Stream for Fuse<S> where
    S: Stream
[src]

impl<S> Stream for Peekable<S> where
    S: Stream
[src]

impl<S> Stream for SelectAll<S> where
    S: Stream
[src]

impl<S> Stream for Skip<S> where
    S: Stream
[src]

impl<S> Stream for SplitStream<S> where
    S: Stream
[src]

impl<S> Stream for Take<S> where
    S: Stream
[src]

impl<S, E> Stream for SinkErrInto<S, E> where
    S: Stream + Sink
[src]

impl<S, E> Stream for ErrInto<S, E> where
    S: Stream,
    <S as Stream>::Error: Into<E>, 
[src]

impl<S, F> Stream for SinkMapErr<S, F> where
    S: Stream
[src]

impl<S, F> Stream for Inspect<S, F> where
    F: FnMut(&<S as Stream>::Item),
    S: Stream
[src]

impl<S, F> Stream for InspectErr<S, F> where
    F: FnMut(&<S as Stream>::Error),
    S: Stream
[src]

impl<S, F, U> Stream for Map<S, F> where
    F: FnMut(<S as Stream>::Item) -> U,
    S: Stream
[src]

impl<S, F, U> Stream for MapErr<S, F> where
    F: FnMut(<S as Stream>::Error) -> U,
    S: Stream
[src]

impl<S, R, F, B> Stream for FilterMap<S, R, F> where
    F: FnMut(<S as Stream>::Item) -> R,
    R: IntoFuture<Item = Option<B>, Error = <S as Stream>::Error>,
    S: Stream
[src]

impl<S, R, P> Stream for Filter<S, R, P> where
    P: FnMut(&<S as Stream>::Item) -> R,
    R: IntoFuture<Item = bool, Error = <S as Stream>::Error>,
    S: Stream
[src]

impl<S, R, P> Stream for SkipWhile<S, R, P> where
    P: FnMut(&<S as Stream>::Item) -> R,
    R: IntoFuture<Item = bool, Error = <S as Stream>::Error>,
    S: Stream
[src]

impl<S, R, P> Stream for TakeWhile<S, R, P> where
    P: FnMut(&<S as Stream>::Item) -> R,
    R: IntoFuture<Item = bool, Error = <S as Stream>::Error>,
    S: Stream
[src]

impl<S, U, F> Stream for AndThen<S, U, F> where
    F: FnMut(<S as Stream>::Item) -> U,
    S: Stream,
    U: IntoFuture<Error = <S as Stream>::Error>, 
[src]

impl<S, U, F> Stream for OrElse<S, U, F> where
    F: FnMut(<S as Stream>::Error) -> U,
    S: Stream,
    U: IntoFuture<Item = <S as Stream>::Item>, 
[src]

impl<S, U, F> Stream for Then<S, U, F> where
    F: FnMut(Result<<S as Stream>::Item, <S as Stream>::Error>) -> U,
    S: Stream,
    U: IntoFuture
[src]

impl<S, U, Fut, F> Stream for With<S, U, Fut, F> where
    F: FnMut(U) -> Fut,
    Fut: IntoFuture,
    S: Stream + Sink
[src]

impl<S, U, St, F> Stream for WithFlatMap<S, U, St, F> where
    F: FnMut(U) -> St,
    S: Stream + Sink,
    St: Stream<Item = <S as Sink>::SinkItem, Error = <S as Sink>::SinkError>, 
[src]

impl<S1, S2> Stream for Chain<S1, S2> where
    S1: Stream,
    S2: Stream<Item = <S1 as Stream>::Item, Error = <S1 as Stream>::Error>, 
[src]

impl<S1, S2> Stream for Select<S1, S2> where
    S1: Stream,
    S2: Stream<Item = <S1 as Stream>::Item, Error = <S1 as Stream>::Error>, 
[src]

impl<S1, S2> Stream for Zip<S1, S2> where
    S1: Stream,
    S2: Stream<Error = <S1 as Stream>::Error>, 
[src]

impl<T> Stream for Receiver<T>
[src]

impl<T> Stream for UnboundedReceiver<T>
[src]

impl<T> Stream for FuturesOrdered<T> where
    T: Future
[src]

impl<T> Stream for FuturesUnordered<T> where
    T: Future
[src]

impl<T, E> Stream for Empty<T, E>
[src]

impl<T, E> Stream for Repeat<T, E> where
    T: Clone
[src]

impl<T, E, F> Stream for PollFn<F> where
    F: FnMut(&mut Context) -> Result<Async<Option<T>>, E>, 
[src]

impl<T, F, Fut, It> Stream for Unfold<T, F, Fut> where
    F: FnMut(T) -> Fut,
    Fut: IntoFuture<Item = Option<(It, T)>>, 
[src]