docs

v0.1.0 문서를 보고 있습니다. 이 버전은 더 이상 지원하지 않습니다. 최신 릴리스: v0.1.3 →

core::stream

이 페이지의 내용

API 참조는 영어로만 있습니다. 표준 라이브러리 소스의 영어 문서 주석에서 만듭니다.

Stream / IntoStream / FromStream.

for await x in s polls s.poll_next(ref ctx) (after s.into_stream() when s has no poll_next) like await, until it is Ready(none).

The adapters are provided methods of Stream returning the structs below (stream::Map<S, U> is not iter::Map). throttle / buffered / buffer_unordered wrap an async yield stream built by a generic helper, the others poll their source directly.

Structs

AsyncStreamSource

pub struct AsyncStream<T>
Trait implementations 2
  • impl<T> Debug for AsyncStream<T>
  • impl<T> Stream for AsyncStream<T>

MapSource

pub struct Map<S, U>

The stream map returns: f of each item.

Trait implementations 2

FilterSource

pub struct Filter<S>

The stream filter returns: the items pred accepts.

Trait implementations 2

TakeSource

pub struct Take<S>

The stream take returns: at most the first n items.

Trait implementations 2

SkipSource

pub struct Skip<S>

The stream skip returns: all but the first n items.

Trait implementations 2

ThrottleSource

pub struct Throttle<S>

The stream throttle returns: the items, at most one per interval.

Trait implementations 2

BufferedSource

pub struct Buffered<S>

The stream buffered returns: the futures' outputs in stream order, up to n running at once.

Trait implementations 2

BufferUnorderedSource

pub struct BufferUnordered<S>

The stream buffer_unordered returns: the futures' outputs in completion order, up to n running at once.

Trait implementations 2

MergeSource

pub struct Merge<S1, S2>

The stream merge returns. Each poll tries the first stream before the second, so a first stream that is always ready starves the second.

Trait implementations 2

SelectSource

pub struct Select<S1, S2>

The stream select returns: merge that ends when either side does.

Trait implementations 2

ZipSource

pub struct Zip<S1, S2>

The stream zip returns: pairs of items, until either side ends.

Trait implementations 2

TryAsyncStreamSource

pub struct TryAsyncStream<T, E>

A throwing stream (async yield fn f() throws (E) -> T): a TryStream whose poll_next throws what the body throws, stepped with try for await x in s { .. }.

Trait implementations 2
  • impl<T, E> Debug for TryAsyncStream<T, E>
  • impl<T, E> TryStream for TryAsyncStream<T, E>

TryMapSource

pub struct TryMap<S, U>

The stream TryStream::map returns: f of each item.

Trait implementations 2

TryFilterSource

pub struct TryFilter<S>

The stream TryStream::filter returns: the items pred accepts.

Trait implementations 2

MapErrSource

pub struct MapErr<S, E2>

The stream map_err returns: each error passed through f.

Trait implementations 2

TryTakeSource

pub struct TryTake<S>

The stream TryStream::take returns: at most the first n items.

Trait implementations 2

TrySkipSource

pub struct TrySkip<S>

The stream TryStream::skip returns: all but the first n items.

Trait implementations 2

ResultsSource

pub struct Results<S>

results's adapter.

Trait implementations 2

FromResultsSource

pub struct FromResults<S, T, E>

The TryStream stream::from_results returns: an Err item is thrown.

Trait implementations 2

Traits

StreamSource

pub trait Stream

An asynchronous source of items: poll_next gives Ready(item), Ready(none) at the end, or Pending. The adapters are lazy.

  • type Item§

    Source
  • fn poll_next(ref self, ref ctx: Context) -> Poll<Item | none>§

    Source

    The next item: Ready(x), Ready(none) once done, or Pending (the waker in ctx is woken when it may be ready).

  • const fn map<U>(self, f: fn(Item) -> U) -> Map<Self, U>§

    Source

    f of each item.

  • const fn filter(self, pred: fn(Item) -> bool) -> Filter<Self>§

    Source

    The items pred accepts.

  • const fn take(self, n: usize) -> Take<Self>§

    Source

    At most the first n items.

  • const fn skip(self, n: usize) -> Skip<Self>§

    Source

    All but the first n items.

  • fn throttle(self, dur: Duration) -> Throttle<Self>§

    Source

    The items, at most one per dur.

  • fn buffered(self, n: usize) -> Buffered<Self> where Item: Future§

    Source

    The outputs of a stream of futures, in stream order, running up to n of them at once.

  • fn buffer_unordered(self, n: usize) -> BufferUnordered<Self> where Item: Future§

    Source

    Like buffered, in completion order.

  • async fn collect<C: FromStream<Item> = List<Item>>(self) -> C§

    Source

    All items gathered into a FromStream collection; a List when the slot does not pick one.

  • async fn for_each(self, f: fn(Item))§

    Source

    f of each item, in order.

IntoStreamSource

pub trait IntoStream

A value for await can walk: into_stream turns it into a stream.

FromStreamSource

pub trait FromStream<T>

collect's target: a collection built from a stream's items.

  • async fn from_stream<S: IntoStream<Item = T>>(s: S) -> Self§

    Source

    Drain s, in order, into a new collection.

TryStreamSource

pub trait TryStream

A stream whose poll_next can fail: an item, none at the end, or a thrown Error (the async TryIterator). try for await x in s { .. } steps it; the try covers the stream and each step, not the body.

  • type Item§

    Source
  • type Error§

    Source
  • fn poll_next(ref self, ref ctx: Context) throws (Error) -> Poll<Item | none>§

    Source

    Resume the body: Ready with the next item (none when done), or Pending; throws what the body throws.

  • const fn map<U>(self, f: fn(Item) throws (Error) -> U) -> TryMap<Self, U>§

    Source

    f of each item.

  • const fn filter(self, pred: fn(Item) throws (Error) -> bool) -> TryFilter<Self>§

    Source

    The items pred accepts.

  • const fn map_err<E2>(self, f: fn(Error) -> E2) -> MapErr<Self, E2>§

    Source

    The same items, each error passed through f.

  • const fn take(self, n: usize) -> TryTake<Self>§

    Source

    At most the first n items.

  • const fn skip(self, n: usize) -> TrySkip<Self>§

    Source

    All but the first n items.

  • const fn results(self) -> Results<Self>§

    Source

    A plain stream of Results: each error becomes a Result::Err item and polling goes on.

  • async fn collect<C: FromStream<Item> = List<Item>>(self) throws (Error) -> C§

    Source

    All items gathered into a FromStream collection; the first error stops it and is thrown.

  • async fn for_each(self, f: fn(Item) throws (Error)) throws (Error)§

    Source

    f of each item, in order.

  • async fn fold<B>(self, init: B, f: fn(B, Item) throws (Error) -> B) throws (Error) -> B§

    Source

    Every item folded into init by f, in order.

Functions

mergeSource

pub const fn merge<S1: Stream, S2: Stream>(a: S1, b: S2) -> Merge<S1, S2>

Both streams' items as they come; ends when both have.

selectSource

pub const fn select<S1: Stream, S2: Stream>(a: S1, b: S2) -> Select<S1, S2>

Like merge, but ends as soon as either stream does.

zipSource

pub const fn zip<S1: Stream, S2: Stream>(a: S1, b: S2) -> Zip<S1, S2>

Pairs of the two streams' items, until either ends.

from_resultsSource

pub const fn from_results<S: Stream<Item = Result<T, E>>, T, E>(s: S) -> FromResults<S, T, E>

A plain stream of Results as a TryStream: an Err item is thrown, then polling goes on.