[][src]Trait async_std::stream::Stream

pub trait Stream {
    type Item;
    fn next<'a>(&'a mut self) -> ImplFuture<'a, Option<Self::Item>>
    where
        Self: Unpin
; fn take(self, n: usize) -> Take<Self>
    where
        Self: Sized
, { ... } }

An asynchronous stream of values.

This trait is an async version of std::iter::Iterator.

While it is currently not possible to implement this trait directly, it gets implemented automatically for all types that implement futures::stream::Stream.

Associated Types

type Item[]

The type of items yielded by this stream.

Required methods

fn next<'a>(&'a mut self) -> ImplFuture<'a, Option<Self::Item>> where
    Self: Unpin
[]

Advances the stream and returns the next value.

Returns None when iteration is finished. Individual stream implementations may choose to resume iteration, and so calling next() again may or may not eventually start returning more values.

Examples

use async_std::prelude::*;
use async_std::stream;

let mut s = stream::once(7);

assert_eq!(s.next().await, Some(7));
assert_eq!(s.next().await, None);

Provided methods

fn take(self, n: usize) -> Take<Self> where
    Self: Sized
[]

Creates a stream that yields its first n elements.

Examples

use async_std::prelude::*;
use async_std::stream;

let mut s = stream::repeat(9).take(3);

while let Some(v) = s.next().await {
    assert_eq!(v, 9);
}

Implementors

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

type Item = Self::Item