Struct futures_concurrency::future::FutureGroup
source · pub struct FutureGroup<F> { /* private fields */ }
Expand description
A growable group of futures which act as a single unit.
§Example
Basic example
use futures_concurrency::future::FutureGroup;
use futures_lite::StreamExt;
use std::future;
let mut group = FutureGroup::new();
group.insert(future::ready(2));
group.insert(future::ready(4));
let mut out = 0;
while let Some(num) = group.next().await {
out += num;
}
assert_eq!(out, 6);
Update the group on every iteration
use futures_concurrency::future::FutureGroup;
use lending_stream::prelude::*;
use std::future;
let mut group = FutureGroup::new();
group.insert(future::ready(4));
let mut index = 3;
let mut out = 0;
let mut group = group.lend_mut();
while let Some((group, num)) = group.next().await {
if index != 0 {
group.insert(future::ready(index));
index -= 1;
}
out += num;
}
assert_eq!(out, 10);
Implementations§
source§impl<F> FutureGroup<F>
impl<F> FutureGroup<F>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new instance of FutureGroup
.
§Example
use futures_concurrency::future::FutureGroup;
let group = FutureGroup::new();
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new instance of FutureGroup
with a given capacity.
§Example
use futures_concurrency::future::FutureGroup;
let group = FutureGroup::with_capacity(2);
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the number of futures currently active in the group.
§Example
use futures_concurrency::future::FutureGroup;
use futures_lite::StreamExt;
use std::future;
let mut group = FutureGroup::with_capacity(2);
assert_eq!(group.len(), 0);
group.insert(future::ready(12));
assert_eq!(group.len(), 1);
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Return the capacity of the FutureGroup
.
§Example
use futures_concurrency::future::FutureGroup;
use futures_lite::stream;
let group = FutureGroup::with_capacity(2);
assert_eq!(group.capacity(), 2);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if there are no futures currently active in the group.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::with_capacity(2);
assert!(group.is_empty());
group.insert(future::ready(12));
assert!(!group.is_empty());
sourcepub fn remove(&mut self, key: Key) -> bool
pub fn remove(&mut self, key: Key) -> bool
Removes a stream from the group. Returns whether the value was present in the group.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::new();
let key = group.insert(future::ready(4));
assert_eq!(group.len(), 1);
group.remove(key);
assert_eq!(group.len(), 0);
sourcepub fn contains_key(&mut self, key: Key) -> bool
pub fn contains_key(&mut self, key: Key) -> bool
Returns true
if the FutureGroup
contains a value for the specified key.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::new();
let key = group.insert(future::ready(4));
assert!(group.contains_key(key));
group.remove(key);
assert!(!group.contains_key(key));
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for additional
more futures to be inserted.
Does nothing if the capacity is already sufficient.
§Example
use futures_concurrency::future::FutureGroup;
use std::future::Ready;
let mut group: FutureGroup<Ready<usize>> = FutureGroup::with_capacity(0);
assert_eq!(group.capacity(), 0);
group.reserve(10);
assert_eq!(group.capacity(), 10);
// does nothing if capacity is sufficient
group.reserve(5);
assert_eq!(group.capacity(), 10);
source§impl<F: Future> FutureGroup<F>
impl<F: Future> FutureGroup<F>
sourcepub fn insert(&mut self, future: F) -> Keywhere
F: Future,
pub fn insert(&mut self, future: F) -> Keywhere
F: Future,
Insert a new future into the group.
§Example
use futures_concurrency::future::FutureGroup;
use std::future;
let mut group = FutureGroup::with_capacity(2);
group.insert(future::ready(12));
sourcepub fn keyed(self) -> Keyed<F>
pub fn keyed(self) -> Keyed<F>
Create a stream which also yields the key of each item.
§Example
use futures_concurrency::future::FutureGroup;
use futures_lite::StreamExt;
use std::future;
let mut group = FutureGroup::new();
group.insert(future::ready(2));
group.insert(future::ready(4));
let mut out = 0;
let mut group = group.keyed();
while let Some((_key, num)) = group.next().await {
out += num;
}
assert_eq!(out, 6);
Trait Implementations§
source§impl<T: Debug> Debug for FutureGroup<T>
impl<T: Debug> Debug for FutureGroup<T>
source§impl<F: Default> Default for FutureGroup<F>
impl<F: Default> Default for FutureGroup<F>
source§fn default() -> FutureGroup<F>
fn default() -> FutureGroup<F>
Returns the “default value” for a type. Read more
source§impl<F: Future> FromIterator<F> for FutureGroup<F>
impl<F: Future> FromIterator<F> for FutureGroup<F>
source§fn from_iter<T: IntoIterator<Item = F>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = F>>(iter: T) -> Self
Creates a value from an iterator. Read more
source§impl<F: Future> Stream for FutureGroup<F>
impl<F: Future> Stream for FutureGroup<F>
impl<'pin, F> Unpin for FutureGroup<F>where
__FutureGroup<'pin, F>: Unpin,
Auto Trait Implementations§
impl<F> Freeze for FutureGroup<F>
impl<F> RefUnwindSafe for FutureGroup<F>where
F: RefUnwindSafe,
impl<F> Send for FutureGroup<F>where
F: Send,
impl<F> Sync for FutureGroup<F>where
F: Sync,
impl<F> UnwindSafe for FutureGroup<F>where
F: UnwindSafe,
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
Mutably borrows from an owned value. Read more
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<S> IntoStream for Swhere
S: Stream,
impl<S> IntoStream for Swhere
S: Stream,
§type IntoStream = S
type IntoStream = S
Which kind of stream are we turning this into?
source§fn into_stream(self) -> S
fn into_stream(self) -> S
Creates a stream from a value.
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self
, then passes self.deref()
into the pipe function.source§impl<S> StreamExt for S
impl<S> StreamExt for S
source§fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
Retrieves the next item in the stream. Read more
source§fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>
Retrieves the next item in the stream. Read more
source§fn count(self) -> CountFuture<Self>where
Self: Sized,
fn count(self) -> CountFuture<Self>where
Self: Sized,
Counts the number of items in the stream. Read more
source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Maps items of the stream to new values using a closure. Read more
source§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
Maps items to streams and then concatenates them. Read more
source§fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>
Maps items of the stream to new values using an async closure. Read more
source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Filters and maps items of the stream using a closure. Read more
source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
Takes only the first
n
items of the stream. Read moresource§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
source§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
Skips the first
n
items of the stream. Read moresource§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
Yields every
step
th item. Read moresource§fn chain<U>(self, other: U) -> Chain<Self, U>
fn chain<U>(self, other: U) -> Chain<Self, U>
Appends another stream to the end of this one. Read more
source§fn collect<C>(self) -> CollectFuture<Self, C>
fn collect<C>(self) -> CollectFuture<Self, C>
Collects all items in the stream into a collection. Read more
source§fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>
Collects all items in the fallible stream into a collection. Read more
source§fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>
Partitions items into those for which
predicate
is true
and those for which it is
false
, and then collects them into two collections. Read moresource§fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>
Accumulates a computation over the stream. Read more
source§fn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F
) -> TryFoldFuture<'_, Self, F, B>
fn try_fold<T, E, F, B>( &mut self, init: B, f: F ) -> TryFoldFuture<'_, Self, F, B>
Accumulates a fallible computation over the stream. Read more
source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
Maps items of the stream to new values using a state value and a closure. Read more
source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Enumerates items, mapping them to
(index, item)
. Read moresource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Calls a closure on each item and passes it on. Read more
source§fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin,
fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin,
Gets the
n
th item of the stream. Read moresource§fn last(self) -> LastFuture<Self>where
Self: Sized,
fn last(self) -> LastFuture<Self>where
Self: Sized,
Returns the last item in the stream. Read more
source§fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>
source§fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>
source§fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>
source§fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>
Calls a closure on each item of the stream. Read more
source§fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>
Calls a fallible closure on each item of the stream, stopping on first error. Read more
source§fn zip<U>(self, other: U) -> Zip<Self, U>
fn zip<U>(self, other: U) -> Zip<Self, U>
Zips up two streams into a single stream of pairs. Read more
source§fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>
Collects a stream of pairs into a pair of collections. Read more
source§fn race<S>(self, other: S) -> Race<Self, S>
fn race<S>(self, other: S) -> Race<Self, S>
Merges with
other
stream, with no preference for either stream when both are ready. Read moresource§impl<S1> StreamExt for S1where
S1: Stream,
impl<S1> StreamExt for S1where
S1: Stream,
source§fn merge<T, S2>(
self,
other: S2
) -> Merge2<T, S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
fn merge<T, S2>(
self,
other: S2
) -> Merge2<T, S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
Combines two streams into a single stream of all their outputs.
source§fn chain<T, S2>(self, other: S2) -> Chain2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
fn chain<T, S2>(self, other: S2) -> Chain2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
Takes two streams and creates a new stream over all in sequence
source§fn zip<T, S2>(self, other: S2) -> Zip2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
fn zip<T, S2>(self, other: S2) -> Zip2<S1, <S2 as IntoStream>::IntoStream>where
S1: Stream<Item = T>,
S2: IntoStream<Item = T>,
‘Zips up’ multiple streams into a single stream of pairs.
source§fn co(self) -> FromStream<Self>where
Self: Sized,
fn co(self) -> FromStream<Self>where
Self: Sized,
Convert into a concurrent stream.
source§fn wait_until<D>(self, deadline: D) -> WaitUntil<Self, D::IntoFuture>where
Self: Sized,
D: IntoFuture,
fn wait_until<D>(self, deadline: D) -> WaitUntil<Self, D::IntoFuture>where
Self: Sized,
D: IntoFuture,
Delay the yielding of items from the stream until the given deadline. Read more
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref()
only in debug builds, and is erased in release
builds.