pub struct FuturesUnordered<Fut> { /* private fields */ }
Expand description

A set of futures which may complete in any order.

See FuturesOrdered for a version of this type that preserves a FIFO order.

This structure is optimized to manage a large number of futures. Futures managed by FuturesUnordered will only be polled when they generate wake-up notifications. This reduces the required amount of work needed to poll large numbers of futures.

FuturesUnordered can be filled by collecting an iterator of futures into a FuturesUnordered, or by pushing futures onto an existing FuturesUnordered. When new futures are added, poll_next must be called in order to begin receiving wake-ups for new futures.

Note that you can create a ready-made FuturesUnordered via the collect method, or you can start with an empty set with the FuturesUnordered::new constructor.

This type is only available when the std or alloc feature of this library is activated, and it is activated by default.

Implementations§

source§

impl<Fut> FuturesUnordered<Fut>

source

pub fn new() -> Self

Constructs a new, empty FuturesUnordered.

The returned FuturesUnordered does not contain any futures. In this state, FuturesUnordered::poll_next will return Poll::Ready(None).

source

pub fn len(&self) -> usize

Returns the number of futures contained in the set.

This represents the total number of in-flight futures.

source

pub fn is_empty(&self) -> bool

Returns true if the set contains no futures.

source

pub fn push(&self, future: Fut)

Push a future into the set.

This method adds the given future to the set. This method will not call poll on the submitted future. The caller must ensure that FuturesUnordered::poll_next is called in order to receive wake-up notifications for the given future.

source

pub fn iter(&self) -> Iter<'_, Fut> where Fut: Unpin,

Returns an iterator that allows inspecting each future in the set.

source

pub fn iter_pin_ref(self: Pin<&Self>) -> IterPinRef<'_, Fut>

Returns an iterator that allows inspecting each future in the set.

source

pub fn iter_mut(&mut self) -> IterMut<'_, Fut> where Fut: Unpin,

Returns an iterator that allows modifying each future in the set.

source

pub fn iter_pin_mut(self: Pin<&mut Self>) -> IterPinMut<'_, Fut>

Returns an iterator that allows modifying each future in the set.

source§

impl<Fut> FuturesUnordered<Fut>

source

pub fn clear(&mut self)

Clears the set, removing all futures.

Trait Implementations§

source§

impl<Fut> Debug for FuturesUnordered<Fut>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Fut> Default for FuturesUnordered<Fut>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<Fut> Drop for FuturesUnordered<Fut>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<Fut> Extend<Fut> for FuturesUnordered<Fut>

source§

fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = Fut>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<Fut> FromIterator<Fut> for FuturesUnordered<Fut>

source§

fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = Fut>,

Creates a value from an iterator. Read more
source§

impl<Fut: Future> FusedStream for FuturesUnordered<Fut>

source§

fn is_terminated(&self) -> bool

Returns true if the stream should no longer be polled.
source§

impl<'a, Fut: Unpin> IntoIterator for &'a FuturesUnordered<Fut>

§

type Item = &'a Fut

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Fut>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, Fut: Unpin> IntoIterator for &'a mut FuturesUnordered<Fut>

§

type Item = &'a mut Fut

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, Fut>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<Fut: Unpin> IntoIterator for FuturesUnordered<Fut>

§

type Item = Fut

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Fut>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl LocalSpawn for FuturesUnordered<LocalFutureObj<'_, ()>>

source§

fn spawn_local_obj( &self, future_obj: LocalFutureObj<'static, ()> ) -> Result<(), SpawnError>

Spawns a future that will be run to completion. Read more
source§

fn status_local(&self) -> Result<(), SpawnError>

Determines whether the executor is able to spawn new tasks. Read more
source§

impl Spawn for FuturesUnordered<FutureObj<'_, ()>>

source§

fn spawn_obj( &self, future_obj: FutureObj<'static, ()> ) -> Result<(), SpawnError>

Spawns a future that will be run to completion. Read more
source§

fn status(&self) -> Result<(), SpawnError>

Determines whether the executor is able to spawn new tasks. Read more
source§

impl<Fut: Future> Stream for FuturesUnordered<Fut>

§

type Item = <Fut as Future>::Output

Values yielded by the stream.
source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more
source§

impl<Fut: Send> Send for FuturesUnordered<Fut>

source§

impl<Fut: Sync> Sync for FuturesUnordered<Fut>

source§

impl<Fut> Unpin for FuturesUnordered<Fut>

Auto Trait Implementations§

§

impl<Fut> !RefUnwindSafe for FuturesUnordered<Fut>

§

impl<Fut> !UnwindSafe for FuturesUnordered<Fut>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<S, T, E> TryStream for Swhere S: Stream<Item = Result<T, E>> + ?Sized,

§

type Ok = T

The type of successful values yielded by this future
§

type Error = E

The type of failures yielded by this future
source§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_> ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more