futures::prelude

Trait Stream

Source
pub trait Stream {
    type Item;
    type Error;

    // Required method
    fn poll_next(
        &mut self,
        cx: &mut Context<'_>,
    ) -> Result<Async<Option<Self::Item>>, Self::Error>;
}
Expand description

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.

Required Associated Types§

Source

type Item

Values yielded by the stream.

Source

type Error

Errors yielded by the stream.

Required Methods§

Source

fn poll_next( &mut self, cx: &mut Context<'_>, ) -> Result<Async<Option<Self::Item>>, Self::Error>

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§

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

fn poll_next( &mut self, cx: &mut Context<'_>, ) -> Result<Async<Option<<&'a mut S as Stream>::Item>>, <&'a mut S as Stream>::Error>

Source§

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

Source§

type Item = <A as Stream>::Item

Source§

type Error = E

Source§

fn poll_next( &mut self, cx: &mut Context<'_>, ) -> Result<Async<Option<<A as Stream>::Item>>, E>

Source§

impl<S> Stream for Box<S>
where S: Stream + ?Sized,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

fn poll_next( &mut self, cx: &mut Context<'_>, ) -> Result<Async<Option<<Box<S> as Stream>::Item>>, <Box<S> as Stream>::Error>

Source§

impl<S> Stream for AssertUnwindSafe<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

fn poll_next( &mut self, cx: &mut Context<'_>, ) -> Result<Async<Option<<S as Stream>::Item>>, <S as Stream>::Error>

Source§

impl<T> Stream for VecDeque<T>

Source§

type Item = T

Source§

type Error = Never

Source§

fn poll_next( &mut self, _cx: &mut Context<'_>, ) -> Result<Async<Option<<VecDeque<T> as Stream>::Item>>, <VecDeque<T> as Stream>::Error>

Implementors§

Source§

impl Stream for Never

Source§

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

Source§

type Item = <A as Stream>::Item

Source§

type Error = <A as Stream>::Error

Source§

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

Source§

type Item = <<F as Future>::Item as Stream>::Item

Source§

type Error = <<F as Future>::Item as Stream>::Error

Source§

impl<F> Stream for IntoStream<F>
where F: Future,

Source§

type Item = <F as Future>::Item

Source§

type Error = <F as Future>::Error

Source§

impl<F> Stream for Once<F>
where F: Future,

Source§

type Item = <F as Future>::Item

Source§

type Error = <F as Future>::Error

Source§

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

Source§

type Item = <I as Iterator>::Item

Source§

type Error = E

Source§

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

Source§

type Item = T

Source§

type Error = E

Source§

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

Source§

type Item = <S1 as Stream>::Item

Source§

type Error = <S1 as Stream>::Error

Source§

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

Source§

type Item = <S1 as Stream>::Item

Source§

type Error = <S1 as Stream>::Error

Source§

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

Source§

type Item = (<S1 as Stream>::Item, <S2 as Stream>::Item)

Source§

type Error = <S1 as Stream>::Error

Source§

impl<S> Stream for Buffer<S>
where S: Sink + Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <<S as Stream>::Item as IntoFuture>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <<S as Stream>::Item as IntoFuture>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<S> Stream for CatchUnwind<S>
where S: Stream + UnwindSafe,

Source§

type Item = Result<<S as Stream>::Item, <S as Stream>::Error>

Source§

type Error = Box<dyn Any + Send>

Source§

impl<S> Stream for Chunks<S>
where S: Stream,

Source§

type Item = Vec<<S as Stream>::Item>

Source§

type Error = <S as Stream>::Error

Source§

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>,

Source§

type Item = <<S as Stream>::Item as Stream>::Item

Source§

type Error = <<S as Stream>::Item as Stream>::Error

Source§

impl<S> Stream for Fuse<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<S> Stream for Peekable<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<S> Stream for SelectAll<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<S> Stream for Skip<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<S> Stream for SplitStream<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<S> Stream for Take<S>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = E

Source§

impl<S, F> Stream for SinkMapErr<S, F>
where S: Stream,

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = U

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = U

Source§

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

Source§

type Item = B

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <U as IntoFuture>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <U as IntoFuture>::Error

Source§

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

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

type Error = <S as Stream>::Error

Source§

impl<T> Stream for Receiver<T>

Source§

impl<T> Stream for UnboundedReceiver<T>

Source§

impl<T> Stream for FuturesOrdered<T>
where T: Future,

Source§

type Item = <T as Future>::Item

Source§

type Error = <T as Future>::Error

Source§

impl<T> Stream for FuturesUnordered<T>
where T: Future,

Source§

type Item = <T as Future>::Item

Source§

type Error = <T as Future>::Error

Source§

impl<T, E> Stream for Empty<T, E>

Source§

type Item = T

Source§

type Error = E

Source§

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

Source§

type Item = T

Source§

type Error = E

Source§

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

Source§

type Item = T

Source§

type Error = E

Source§

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

Source§

type Item = It

Source§

type Error = <Fut as IntoFuture>::Error