Skip to main content

Stream

Trait Stream 

Source
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§

Source

type Item

The type of values yielded by the stream.

Required Methods§

Source

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::Pending means the next value is not ready yet.
  • Poll::Ready(Some(val)) means val is 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.

Provided Methods§

Source

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream.

The default implementation returns (0, None) which is correct for any stream.

Implementations on Foreign Types§

Source§

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

Source§

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

Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Source§

fn size_hint(&self) -> (usize, Option<usize>)

Source§

impl<S: Stream + Unpin + ?Sized> Stream for &mut S

Source§

type Item = <S as Stream>::Item

Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Source§

fn size_hint(&self) -> (usize, Option<usize>)

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Source§

fn size_hint(&self) -> (usize, Option<usize>)

Implementors§

Source§

impl Stream for ReadDir

Source§

impl Stream for RecvStream<'_>

Source§

impl Stream for asupersync::net::tcp::listener::Incoming<'_>

Source§

impl Stream for asupersync::net::unix::listener::Incoming<'_>

Source§

impl<I: Iterator> Stream for Iter<I>

Source§

type Item = <I as Iterator>::Item

Source§

impl<L: TcpListenerApi> Stream for IncomingStream<'_, L>

Source§

impl<R, D> Stream for FramedRead<R, D>
where R: AsyncRead + Unpin, D: Decoder + Unpin,

Source§

type Item = Result<<D as Decoder>::Item, <D as Decoder>::Error>

Source§

impl<R: AsyncBufRead + Unpin> Stream for asupersync::io::Lines<R>

Source§

impl<R: AsyncRead + Unpin> Stream for asupersync::fs::Lines<R>

Source§

impl<R: AsyncRead + Unpin> Stream for ReaderStream<R>

Source§

impl<S1, S2> Stream for Chain<S1, S2>
where S1: Stream + Unpin, S2: Stream<Item = S1::Item> + Unpin,

Source§

type Item = <S1 as Stream>::Item

Source§

impl<S1, S2> Stream for Zip<S1, S2>
where S1: Stream, S2: Stream,

Source§

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

Source§

impl<S> Stream for BufferUnordered<S>
where S: Stream + Unpin, S::Item: Future + Unpin,

Source§

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

Source§

impl<S> Stream for Buffered<S>
where S: Stream + Unpin, S::Item: Future + Unpin,

Source§

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

Source§

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

Source§

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

Source§

impl<S> Stream for Merge<S>
where S: Stream + Unpin,

Source§

type Item = <S as Stream>::Item

Source§

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

Source§

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

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

impl<S, F> Stream for SkipWhile<S, F>
where S: Stream, F: FnMut(&S::Item) -> bool,

Source§

type Item = <S as Stream>::Item

Source§

impl<S, F> Stream for TakeWhile<S, F>
where S: Stream, F: FnMut(&S::Item) -> bool,

Source§

type Item = <S as Stream>::Item

Source§

impl<S, F, T> Stream for FilterMap<S, F>
where S: Stream, F: FnMut(S::Item) -> Option<T>,

Source§

type Item = T

Source§

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

Source§

type Item = T

Source§

impl<S, Fut, F> Stream for Then<S, Fut, F>
where S: Stream, F: FnMut(S::Item) -> Fut, Fut: Future,

Source§

type Item = <Fut as Future>::Output

Source§

impl<S, P> Stream for Filter<S, P>
where S: Stream, P: FnMut(&S::Item) -> bool,

Source§

type Item = <S as Stream>::Item

Source§

impl<S, St, B, F> Stream for Scan<S, St, F>
where S: Stream, F: FnMut(&mut St, S::Item) -> Option<B>,

Source§

type Item = B

Source§

impl<S: Stream> Stream for Debounce<S>

Source§

type Item = <S as Stream>::Item

Source§

impl<S: Stream> Stream for Enumerate<S>

Source§

type Item = (usize, <S as Stream>::Item)

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

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

Source§

type Item = <S as Stream>::Item

Source§

impl<S: Stream> Stream for Throttle<S>

Source§

type Item = <S as Stream>::Item

Source§

impl<T> Stream for ReceiverStream<T>

Source§

type Item = T

Source§

impl<T, U> Stream for Framed<T, U>
where T: AsyncRead + Unpin, U: Decoder + Unpin,

Source§

type Item = Result<<U as Decoder>::Item, <U as Decoder>::Error>

Source§

impl<T: Clone> Stream for BroadcastStream<T>

Source§

impl<T: Clone> Stream for WatchStream<T>

Source§

type Item = T