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>MapSource
pub struct Map<S, U>The stream map returns: f of each item.
FilterSource
pub struct Filter<S>The stream filter returns: the items pred accepts.
TakeSource
pub struct Take<S>The stream take returns: at most the first n items.
SkipSource
pub struct Skip<S>The stream skip returns: all but the first n items.
ThrottleSource
pub struct Throttle<S>The stream throttle returns: the items, at most one per interval.
BufferedSource
pub struct Buffered<S>The stream buffered returns: the futures' outputs in stream order,
up to n running at once.
BufferUnorderedSource
pub struct BufferUnordered<S>The stream buffer_unordered returns: the futures' outputs in
completion order, up to n running at once.
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.
SelectSource
pub struct Select<S1, S2>The stream select returns: merge that ends when either side does.
ZipSource
pub struct Zip<S1, S2>The stream zip returns: pairs of items, until either side ends.
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 { .. }.
TryMapSource
pub struct TryMap<S, U>The stream TryStream::map returns: f of each item.
TryFilterSource
pub struct TryFilter<S>The stream TryStream::filter returns: the items pred accepts.
MapErrSource
pub struct MapErr<S, E2>The stream map_err returns: each error passed through f.
TryTakeSource
pub struct TryTake<S>The stream TryStream::take returns: at most the first n items.
TrySkipSource
pub struct TrySkip<S>The stream TryStream::skip returns: all but the first n items.
ResultsSource
pub struct Results<S>results's adapter.
FromResultsSource
pub struct FromResults<S, T, E>The TryStream stream::from_results returns: an Err item is
thrown.
Traits
StreamSource
pub trait StreamAn asynchronous source of items: poll_next gives Ready(item),
Ready(none) at the end, or Pending. The adapters are lazy.
The next item:
Ready(x),Ready(none)once done, orPending(the waker inctxis woken when it may be ready).fof each item.The items
predaccepts.At most the first
nitems.All but the first
nitems.The items, at most one per
dur.The outputs of a stream of futures, in stream order, running up to
nof them at once.
Sourcefn buffer_unordered(§self, n: usize) -> BufferUnordered<Self> where Item: Future Like
buffered, in completion order.
Sourceasync fn collect<C: FromStream<Item> = List<Item>>(§self) -> C All items gathered into a
FromStreamcollection; aListwhen the slot does not pick one.fof each item, in order.
IntoStreamSource
pub trait IntoStreamA value for await can walk: into_stream turns it into a stream.
A stream over the value.
FromStreamSource
pub trait FromStream<T>collect's target: a collection built from a stream's items.
Sourceasync fn from_stream<S: IntoStream<Item = T>>(§s: S) -> Self Drain
s, in order, into a new collection.
TryStreamSource
pub trait TryStreamA 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.
Resume the body:
Readywith the next item (nonewhen done), orPending; throws what the body throws.fof each item.The items
predaccepts.The same items, each error passed through
f.At most the first
nitems.All but the first
nitems.A plain stream of
Results: each error becomes aResult::Erritem and polling goes on.
Sourceasync fn collect<C: FromStream<Item> = List<Item>>(§self) throws (Error) -> C All items gathered into a
FromStreamcollection; the first error stops it and is thrown.fof each item, in order.Every item folded into
initbyf, 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.