pub struct StreamUnordered<S> { /* private fields */ }Expand description
A set of streams which may yield items in any order.
This structure is optimized to manage a large number of streams.
Streams managed by StreamUnordered will only be polled when they
generate wake-up notifications. This reduces the required amount of work
needed to poll large numbers of streams.
StreamUnordered can be filled by collecting an
iterator of streams into a StreamUnordered, or by
inserting streams onto an existing
StreamUnordered. When new streams are added,
poll_next must be called in order to begin receiving
wake-ups for new streams.
Note that you can create a ready-made StreamUnordered via the
collect method, or you can start with an empty set
with the StreamUnordered::new constructor.
Implementations§
Source§impl<S: Stream> StreamUnordered<S>
 
impl<S: Stream> StreamUnordered<S>
Sourcepub fn new() -> StreamUnordered<S>
 
pub fn new() -> StreamUnordered<S>
Constructs a new, empty StreamUnordered.
The returned StreamUnordered does not contain any streams.
In this state, StreamUnordered::poll_next will
return Poll::Ready(None).
Source§impl<S> StreamUnordered<S>
 
impl<S> StreamUnordered<S>
Sourcepub fn len(&self) -> usize
 
pub fn len(&self) -> usize
Returns the number of streams contained in the set.
This represents the total number of in-flight streams.
Sourcepub fn stream_entry(&mut self) -> StreamEntry<'_, S>
 
pub fn stream_entry(&mut self) -> StreamEntry<'_, S>
Returns a handle to a vacant stream entry allowing for further manipulation.
This function is useful when creating values that must contain their stream token. The
returned StreamEntry reserves an entry for the stream and is able to query the associated
token.
Sourcepub fn push(&mut self, stream: S) -> usize
 👎Deprecated since 0.5.2: Prefer StreamUnordered::insert
pub fn push(&mut self, stream: S) -> usize
Insert a stream into the set.
A deprecated synonym for [insert].
Sourcepub fn insert(&mut self, stream: S) -> usize
 
pub fn insert(&mut self, stream: S) -> usize
Insert a stream into the set.
This method adds the given stream to the set. This method will not call
poll_next on the submitted stream. The caller
must ensure that StreamUnordered::poll_next is called in order to
receive wake-up notifications for the given stream.
The returned token is an identifier that uniquely identifies the given stream in the
current set. To get a handle to the inserted stream, pass the token to
StreamUnordered::get, StreamUnordered::get_mut, or StreamUnordered::get_pin_mut
(or just index StreamUnordered directly). The same token will be yielded whenever an
element is pulled from this stream.
Note that the streams are not ordered, and may not be yielded back in insertion or token order when you iterate over them.
Sourcepub fn remove(self: Pin<&mut Self>, token: usize) -> bool
 
pub fn remove(self: Pin<&mut Self>, token: usize) -> bool
Remove a stream from the set.
The stream will be dropped and will no longer yield stream events.
Sourcepub fn take(self: Pin<&mut Self>, token: usize) -> Option<S>where
    S: Unpin,
 
pub fn take(self: Pin<&mut Self>, token: usize) -> Option<S>where
    S: Unpin,
Remove and return a stream from the set.
The stream will no longer be polled, and will no longer yield stream events.
Note that since this method moves S, which we may have given out a Pin to, it requires
that S is Unpin.
Sourcepub fn is_finished(&self, token: usize) -> Option<bool>
 
pub fn is_finished(&self, token: usize) -> Option<bool>
Returns true if the stream with the given token has yielded None.
Sourcepub fn get(&self, token: usize) -> Option<&S>
 
pub fn get(&self, token: usize) -> Option<&S>
Returns a reference to the stream with the given token
Sourcepub fn get_mut(&mut self, token: usize) -> Option<&mut S>where
    S: Unpin,
 
pub fn get_mut(&mut self, token: usize) -> Option<&mut S>where
    S: Unpin,
Returns a reference that allows modifying the stream with the given token.
Sourcepub fn get_pin_mut(self: Pin<&mut Self>, token: usize) -> Option<Pin<&mut S>>
 
pub fn get_pin_mut(self: Pin<&mut Self>, token: usize) -> Option<Pin<&mut S>>
Returns a pinned reference that allows modifying the stream with the given token.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, S> ⓘwhere
    S: Unpin,
 
pub fn iter_mut(&mut self) -> IterMut<'_, S> ⓘwhere
    S: Unpin,
Returns an iterator that allows modifying each stream in the set.
Sourcepub fn iter_mut_with_token(&mut self) -> IterMutWithToken<'_, S> ⓘwhere
    S: Unpin,
 
pub fn iter_mut_with_token(&mut self) -> IterMutWithToken<'_, S> ⓘwhere
    S: Unpin,
Returns an iterator that allows modifying each stream in the set.
Sourcepub fn iter_pin_mut(self: Pin<&mut Self>) -> IterPinMut<'_, S> ⓘ
 
pub fn iter_pin_mut(self: Pin<&mut Self>) -> IterPinMut<'_, S> ⓘ
Returns an iterator that allows modifying each stream in the set.
Sourcepub fn iter_pin_mut_with_token(
    self: Pin<&mut Self>,
) -> IterPinMutWithToken<'_, S> ⓘ
 
pub fn iter_pin_mut_with_token( self: Pin<&mut Self>, ) -> IterPinMutWithToken<'_, S> ⓘ
Returns an iterator that allows modifying each stream in the set.
Sourcepub fn iter_with_token(&self) -> IterWithToken<'_, S> ⓘ
 
pub fn iter_with_token(&self) -> IterWithToken<'_, S> ⓘ
Returns an immutable iterator that allows getting a reference to each stream in the set.
Trait Implementations§
Source§impl<S> Debug for StreamUnordered<S>
 
impl<S> Debug for StreamUnordered<S>
Source§impl<S: Stream> Default for StreamUnordered<S>
 
impl<S: Stream> Default for StreamUnordered<S>
Source§fn default() -> StreamUnordered<S>
 
fn default() -> StreamUnordered<S>
Source§impl<S> Drop for StreamUnordered<S>
 
impl<S> Drop for StreamUnordered<S>
Source§impl<S: Stream> FromIterator<S> for StreamUnordered<S>
 
impl<S: Stream> FromIterator<S> for StreamUnordered<S>
Source§fn from_iter<I>(iter: I) -> Selfwhere
    I: IntoIterator<Item = S>,
 
fn from_iter<I>(iter: I) -> Selfwhere
    I: IntoIterator<Item = S>,
Source§impl<S: Stream + 'static> FusedStream for StreamUnordered<S>
 
impl<S: Stream + 'static> FusedStream for StreamUnordered<S>
Source§fn is_terminated(&self) -> bool
 
fn is_terminated(&self) -> bool
true if the stream should no longer be polled.Source§impl<S> Index<usize> for StreamUnordered<S>
 
impl<S> Index<usize> for StreamUnordered<S>
Source§impl<S: Stream + 'static> Stream for StreamUnordered<S>
 
impl<S: Stream + 'static> Stream for StreamUnordered<S>
Source§type Item = (StreamYield<S>, usize)
 
type Item = (StreamYield<S>, usize)
impl<S: Send> Send for StreamUnordered<S>
impl<S: Sync> Sync for StreamUnordered<S>
impl<S> Unpin for StreamUnordered<S>
Auto Trait Implementations§
impl<S> !Freeze for StreamUnordered<S>
impl<S> !RefUnwindSafe for StreamUnordered<S>
impl<S> !UnwindSafe for StreamUnordered<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> StreamExt for T
 
impl<T> StreamExt for T
Source§fn next(&mut self) -> Next<'_, Self>where
    Self: Unpin,
 
fn next(&mut self) -> Next<'_, Self>where
    Self: Unpin,
Source§fn into_future(self) -> StreamFuture<Self>
 
fn into_future(self) -> StreamFuture<Self>
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
 
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn enumerate(self) -> Enumerate<Self>where
    Self: Sized,
 
fn enumerate(self) -> Enumerate<Self>where
    Self: Sized,
Source§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
 
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
Source§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
 
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
 
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
Source§fn collect<C>(self) -> Collect<Self, C>
 
fn collect<C>(self) -> Collect<Self, C>
Source§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
 
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
Source§fn concat(self) -> Concat<Self>
 
fn concat(self) -> Concat<Self>
Source§fn count(self) -> Count<Self>where
    Self: Sized,
 
fn count(self) -> Count<Self>where
    Self: Sized,
Source§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
 
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
Source§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
 
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
true if any element in stream satisfied a predicate. Read moreSource§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
 
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
true if all element in stream satisfied a predicate. Read moreSource§fn flatten(self) -> Flatten<Self>
 
fn flatten(self) -> Flatten<Self>
Source§fn flatten_unordered(
    self,
    limit: impl Into<Option<usize>>,
) -> FlattenUnorderedWithFlowController<Self, ()>
 
fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
Source§fn flat_map_unordered<U, F>(
    self,
    limit: impl Into<Option<usize>>,
    f: F,
) -> FlatMapUnordered<Self, U, F>
 
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
StreamExt::map but flattens nested Streams
and polls them concurrently, yielding items in any order, as they made
available. Read moreSource§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
 
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
StreamExt::fold that holds internal state
and produces a new stream. Read moreSource§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
 
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
true. Read moreSource§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
 
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
true. Read moreSource§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
 
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
Source§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
 
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
Source§fn for_each_concurrent<Fut, F>(
    self,
    limit: impl Into<Option<usize>>,
    f: F,
) -> ForEachConcurrent<Self, Fut, F>
 
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F>
Source§fn take(self, n: usize) -> Take<Self>where
    Self: Sized,
 
fn take(self, n: usize) -> Take<Self>where
    Self: Sized,
n items of the underlying stream. Read moreSource§fn skip(self, n: usize) -> Skip<Self>where
    Self: Sized,
 
fn skip(self, n: usize) -> Skip<Self>where
    Self: Sized,
n items of the underlying stream. Read moreSource§fn catch_unwind(self) -> CatchUnwind<Self>where
    Self: Sized + UnwindSafe,
 
fn catch_unwind(self) -> CatchUnwind<Self>where
    Self: Sized + UnwindSafe,
Source§fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
 
fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
    Self: Sized + 'a,
 
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
    Self: Sized + 'a,
Source§fn buffered(self, n: usize) -> Buffered<Self>
 
fn buffered(self, n: usize) -> Buffered<Self>
Source§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
 
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
Source§fn zip<St>(self, other: St) -> Zip<Self, St>
 
fn zip<St>(self, other: St) -> Zip<Self, St>
Source§fn peekable(self) -> Peekable<Self>where
    Self: Sized,
 
fn peekable(self) -> Peekable<Self>where
    Self: Sized,
peek method. Read moreSource§fn chunks(self, capacity: usize) -> Chunks<Self>where
    Self: Sized,
 
fn chunks(self, capacity: usize) -> Chunks<Self>where
    Self: Sized,
Source§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
    Self: Sized,
 
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
    Self: Sized,
Source§fn forward<S>(self, sink: S) -> Forward<Self, S>
 
fn forward<S>(self, sink: S) -> Forward<Self, S>
Source§fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
 
fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
Source§fn inspect<F>(self, f: F) -> Inspect<Self, F>
 
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn left_stream<B>(self) -> Either<Self, B>
 
fn left_stream<B>(self) -> Either<Self, B>
Source§fn right_stream<B>(self) -> Either<B, Self>
 
fn right_stream<B>(self) -> Either<B, Self>
Source§fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
    Self: Unpin,
 
fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
    Self: Unpin,
Stream::poll_next on Unpin
stream types.