Trait bevy_internal::tasks::prelude::ParallelIterator
source · pub trait ParallelIterator<BatchIter>: Sized + Send{
Show 32 methods
// Required method
fn next_batch(&mut self) -> Option<BatchIter>;
// Provided methods
fn size_hint(&self) -> (usize, Option<usize>) { ... }
fn count(self, pool: &TaskPool) -> usize { ... }
fn last(self, _pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item> { ... }
fn nth(
self,
_pool: &TaskPool,
n: usize
) -> Option<<BatchIter as Iterator>::Item> { ... }
fn chain<U>(self, other: U) -> Chain<Self, U>
where U: ParallelIterator<BatchIter> { ... }
fn map<T, F>(self, f: F) -> Map<Self, F>
where F: FnMut(<BatchIter as Iterator>::Item) -> T + Send + Clone { ... }
fn for_each<F>(self, pool: &TaskPool, f: F)
where F: FnMut(<BatchIter as Iterator>::Item) + Send + Clone + Sync { ... }
fn filter<F>(self, predicate: F) -> Filter<Self, F>
where F: FnMut(&<BatchIter as Iterator>::Item) -> bool { ... }
fn filter_map<R, F>(self, f: F) -> FilterMap<Self, F>
where F: FnMut(<BatchIter as Iterator>::Item) -> Option<R> { ... }
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F>
where F: FnMut(<BatchIter as Iterator>::Item) -> U,
U: IntoIterator { ... }
fn flatten(self) -> Flatten<Self>
where <BatchIter as Iterator>::Item: IntoIterator { ... }
fn fuse(self) -> Fuse<Self> { ... }
fn inspect<F>(self, f: F) -> Inspect<Self, F>
where F: FnMut(&<BatchIter as Iterator>::Item) { ... }
fn by_ref(&mut self) -> &mut Self { ... }
fn collect<C>(self, pool: &TaskPool) -> C
where C: FromIterator<<BatchIter as Iterator>::Item>,
<BatchIter as Iterator>::Item: Send + 'static { ... }
fn partition<C, F>(self, pool: &TaskPool, f: F) -> (C, C)
where C: Default + Extend<<BatchIter as Iterator>::Item> + Send,
F: FnMut(&<BatchIter as Iterator>::Item) -> bool + Send + Sync + Clone,
<BatchIter as Iterator>::Item: Send + 'static { ... }
fn fold<C, F, D>(self, pool: &TaskPool, init: C, f: F) -> Vec<C>
where F: FnMut(C, <BatchIter as Iterator>::Item) -> C + Send + Sync + Clone,
C: Clone + Send + Sync + 'static { ... }
fn all<F>(self, pool: &TaskPool, f: F) -> bool
where F: FnMut(<BatchIter as Iterator>::Item) -> bool + Send + Sync + Clone { ... }
fn any<F>(self, pool: &TaskPool, f: F) -> bool
where F: FnMut(<BatchIter as Iterator>::Item) -> bool + Send + Sync + Clone { ... }
fn position<F>(self, pool: &TaskPool, f: F) -> Option<usize>
where F: FnMut(<BatchIter as Iterator>::Item) -> bool + Send + Sync + Clone { ... }
fn max(self, pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
where <BatchIter as Iterator>::Item: Ord + Send + 'static { ... }
fn min(self, pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
where <BatchIter as Iterator>::Item: Ord + Send + 'static { ... }
fn max_by_key<R, F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
where R: Ord,
F: FnMut(&<BatchIter as Iterator>::Item) -> R + Send + Sync + Clone,
<BatchIter as Iterator>::Item: Send + 'static { ... }
fn max_by<F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
where F: FnMut(&<BatchIter as Iterator>::Item, &<BatchIter as Iterator>::Item) -> Ordering + Send + Sync + Clone,
<BatchIter as Iterator>::Item: Send + 'static { ... }
fn min_by_key<R, F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
where R: Ord,
F: FnMut(&<BatchIter as Iterator>::Item) -> R + Send + Sync + Clone,
<BatchIter as Iterator>::Item: Send + 'static { ... }
fn min_by<F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
where F: FnMut(&<BatchIter as Iterator>::Item, &<BatchIter as Iterator>::Item) -> Ordering + Send + Sync + Clone,
<BatchIter as Iterator>::Item: Send + 'static { ... }
fn copied<'a, T>(self) -> Copied<Self>
where Self: ParallelIterator<BatchIter>,
T: 'a + Copy { ... }
fn cloned<'a, T>(self) -> Cloned<Self>
where Self: ParallelIterator<BatchIter>,
T: 'a + Copy { ... }
fn cycle(self) -> Cycle<Self>
where Self: Clone { ... }
fn sum<S, R>(self, pool: &TaskPool) -> R
where S: Sum<<BatchIter as Iterator>::Item> + Send + 'static,
R: Sum<S> { ... }
fn product<S, R>(self, pool: &TaskPool) -> R
where S: Product<<BatchIter as Iterator>::Item> + Send + 'static,
R: Product<S> { ... }
}
Expand description
ParallelIterator
closely emulates the std::iter::Iterator
interface. However, it uses bevy_task
to compute batches in parallel.
Note that the overhead of ParallelIterator
is high relative to some
workloads. In particular, if the batch size is too small or task being
run in parallel is inexpensive, a ParallelIterator
could take longer
than a normal Iterator
. Therefore, you should profile your code before
using ParallelIterator
.
Required Methods§
sourcefn next_batch(&mut self) -> Option<BatchIter>
fn next_batch(&mut self) -> Option<BatchIter>
Returns the next batch of items for processing.
Each batch is an iterator with items of the same type as the
ParallelIterator
. Returns None
when there are no batches left.
Provided Methods§
sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds on the remaining number of items in the parallel iterator.
sourcefn count(self, pool: &TaskPool) -> usize
fn count(self, pool: &TaskPool) -> usize
Consumes the parallel iterator and returns the number of items.
sourcefn last(self, _pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
fn last(self, _pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
Consumes the parallel iterator and returns the last item.
See Iterator::last()
sourcefn nth(
self,
_pool: &TaskPool,
n: usize
) -> Option<<BatchIter as Iterator>::Item>
fn nth( self, _pool: &TaskPool, n: usize ) -> Option<<BatchIter as Iterator>::Item>
Consumes the parallel iterator and returns the nth item.
See Iterator::nth()
sourcefn chain<U>(self, other: U) -> Chain<Self, U>where
U: ParallelIterator<BatchIter>,
fn chain<U>(self, other: U) -> Chain<Self, U>where
U: ParallelIterator<BatchIter>,
Takes two parallel iterators and returns a parallel iterators over both in sequence.
sourcefn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Takes a closure and creates a parallel iterator which calls that closure on each item.
See Iterator::map()
sourcefn for_each<F>(self, pool: &TaskPool, f: F)
fn for_each<F>(self, pool: &TaskPool, f: F)
Calls a closure on each item of a parallel iterator.
sourcefn filter<F>(self, predicate: F) -> Filter<Self, F>
fn filter<F>(self, predicate: F) -> Filter<Self, F>
Creates a parallel iterator which uses a closure to determine if an element should be yielded.
sourcefn filter_map<R, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<R, F>(self, f: F) -> FilterMap<Self, F>
Creates a parallel iterator that both filters and maps.
sourcefn flat_map<U, F>(self, f: F) -> FlatMap<Self, F>
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, F>
Creates a parallel iterator that works like map, but flattens nested structure.
sourcefn fuse(self) -> Fuse<Self>
fn fuse(self) -> Fuse<Self>
Creates a parallel iterator which ends after the first None.
See Iterator::fuse()
sourcefn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Does something with each item of a parallel iterator, passing the value on.
sourcefn partition<C, F>(self, pool: &TaskPool, f: F) -> (C, C)
fn partition<C, F>(self, pool: &TaskPool, f: F) -> (C, C)
Consumes a parallel iterator, creating two collections from it.
sourcefn fold<C, F, D>(self, pool: &TaskPool, init: C, f: F) -> Vec<C>
fn fold<C, F, D>(self, pool: &TaskPool, init: C, f: F) -> Vec<C>
Repeatedly applies a function to items of each batch of a parallel iterator, producing a Vec of final values.
Note that this folds each batch independently and returns a Vec of results (in batch order).
See Iterator::fold()
sourcefn all<F>(self, pool: &TaskPool, f: F) -> bool
fn all<F>(self, pool: &TaskPool, f: F) -> bool
Tests if every element of the parallel iterator matches a predicate.
Note that all is not short circuiting.
See Iterator::all()
sourcefn any<F>(self, pool: &TaskPool, f: F) -> bool
fn any<F>(self, pool: &TaskPool, f: F) -> bool
Tests if any element of the parallel iterator matches a predicate.
Note that any is not short circuiting.
See Iterator::any()
sourcefn position<F>(self, pool: &TaskPool, f: F) -> Option<usize>
fn position<F>(self, pool: &TaskPool, f: F) -> Option<usize>
Searches for an element in a parallel iterator, returning its index.
Note that position consumes the whole iterator.
sourcefn max(self, pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
fn max(self, pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
Returns the maximum item of a parallel iterator.
See Iterator::max()
sourcefn min(self, pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
fn min(self, pool: &TaskPool) -> Option<<BatchIter as Iterator>::Item>
Returns the minimum item of a parallel iterator.
See Iterator::min()
sourcefn max_by_key<R, F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
fn max_by_key<R, F>( self, pool: &TaskPool, f: F ) -> Option<<BatchIter as Iterator>::Item>
Returns the item that gives the maximum value from the specified function.
sourcefn max_by<F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
fn max_by<F>( self, pool: &TaskPool, f: F ) -> Option<<BatchIter as Iterator>::Item>
Returns the item that gives the maximum value with respect to the specified comparison function.
sourcefn min_by_key<R, F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
fn min_by_key<R, F>( self, pool: &TaskPool, f: F ) -> Option<<BatchIter as Iterator>::Item>
Returns the item that gives the minimum value from the specified function.
sourcefn min_by<F>(
self,
pool: &TaskPool,
f: F
) -> Option<<BatchIter as Iterator>::Item>
fn min_by<F>( self, pool: &TaskPool, f: F ) -> Option<<BatchIter as Iterator>::Item>
Returns the item that gives the minimum value with respect to the specified comparison function.
sourcefn copied<'a, T>(self) -> Copied<Self>where
Self: ParallelIterator<BatchIter>,
T: 'a + Copy,
fn copied<'a, T>(self) -> Copied<Self>where
Self: ParallelIterator<BatchIter>,
T: 'a + Copy,
Creates a parallel iterator which copies all of its items.
sourcefn cloned<'a, T>(self) -> Cloned<Self>where
Self: ParallelIterator<BatchIter>,
T: 'a + Copy,
fn cloned<'a, T>(self) -> Cloned<Self>where
Self: ParallelIterator<BatchIter>,
T: 'a + Copy,
Creates a parallel iterator which clones all of its items.
sourcefn sum<S, R>(self, pool: &TaskPool) -> R
fn sum<S, R>(self, pool: &TaskPool) -> R
Sums the items of a parallel iterator.
See Iterator::sum()