Module async_utils::stream
source · Expand description
Additional Useful Stream Combinators and Utilities
Streams always signal exhaustion with None
return values. A stream epitaph can be used when
a specific value is desired as the last item returned by a stream before it is exhausted.
Example usecase: often streams will be used without having direct access to the stream itself
such as from a streammap::StreamMap
or a futures::stream::FuturesUnordered
. Occasionally,
it is necessary to perform some cleanup procedure outside of a stream when it is exhausted. An
epitaph
can be used to uniquely identify which stream has ended within a collection of
streams.
Structs
- A stream that selects items from a [
Stream
] of [Stream
]s. - A collection of Future indexed by key, allowing removal by Key. When polled, a FutureMap yields from whichever member future is ready first. The Future type
Fut
can be?Unpin
, as all futures are stored as pins inside the map. The Key typeK
must beUnpin
; it is unlikely that an!Unpin
type would ever be needed as a Key. FutureMap yields items of type Fut::Output. - A collection of multiple futures that optimizes for the single-future case.
- A collection of Stream indexed by key, allowing removal by Key. When polled, a StreamMap yields from whichever member stream is ready first. The Stream type
St
can be?Unpin
, as all streams are stored as pins inside the map. The Key typeK
must beUnpin
; it is unlikely that an!Unpin
type would ever be needed as a Key. StreamMap yields items of type St::Item; For a stream that yields messages tagged with their Key, consider using theIndexedStreams
type alias or using theTagged
combinator. - A
Stream
that returns the values of the wrapped stream until the wrapped stream is exhausted. Then it returns a single epitaph value before being exhausted - A Stream where each yielded item is tagged with a uniform key Items yielded are (K, St::Item)
- A try stream that selects items from a [
TryStream
] of [TryStream
]s.
Enums
- Values returned from a stream with an epitaph are of type
StreamItem
.
Traits
- Extension trait to allow for easy creation of a
FlattenUnordered
stream from aStream
. - Extension trait to allow for easy creation of a
TryFlattenUnordered
stream from aStream
. - Extension trait to allow for easy creation of a
StreamWithEpitaph
from aStream
. - Extension trait to allow for easy creation of a
Tagged
stream from aStream
.
Type Aliases
- Convenient alias for a collection of Streams indexed by key where each message is tagged and stream termination is notified by key. This is especially useful for maintaining a collection of fidl client request streams, and being notified when each terminates