Trait bevy::tasks::ParallelSliceMut

pub trait ParallelSliceMut<T>: AsMut<[T]>
where T: Send,
{ // Provided methods fn par_chunk_map_mut<F, R>( &mut self, task_pool: &TaskPool, chunk_size: usize, f: F ) -> Vec<R> where F: Fn(usize, &mut [T]) -> R + Send + Sync, R: Send + 'static { ... } fn par_splat_map_mut<F, R>( &mut self, task_pool: &TaskPool, max_tasks: Option<usize>, f: F ) -> Vec<R> where F: Fn(usize, &mut [T]) -> R + Send + Sync, R: Send + 'static { ... } }
Expand description

Provides functions for mapping mutable slices across a provided TaskPool.

Provided Methods§

fn par_chunk_map_mut<F, R>( &mut self, task_pool: &TaskPool, chunk_size: usize, f: F ) -> Vec<R>
where F: Fn(usize, &mut [T]) -> R + Send + Sync, R: Send + 'static,

Splits the slice in chunks of size chunks_size or less and maps the chunks in parallel across the provided task_pool. One task is spawned in the task pool for every chunk.

The iteration function takes the index of the chunk in the original slice as the first argument, and the chunk as the second argument.

Returns a Vec of the mapped results in the same order as the input.

§Example
let task_pool = TaskPool::new();
let mut counts = (0..10000).collect::<Vec<u32>>();
let incremented = counts.par_chunk_map_mut(&task_pool, 100, |_index, chunk| {
  let mut results = Vec::new();
  for count in chunk {
    *count += 5;
    results.push(*count - 2);
  }
  results
});

assert_eq!(counts, (5..10005).collect::<Vec<u32>>());
§See Also

ParallelSlice::par_chunk_map for mapping immutable slices. ParallelSliceMut::par_splat_map_mut for mapping when a specific chunk size is unknown.

fn par_splat_map_mut<F, R>( &mut self, task_pool: &TaskPool, max_tasks: Option<usize>, f: F ) -> Vec<R>
where F: Fn(usize, &mut [T]) -> R + Send + Sync, R: Send + 'static,

Splits the slice into a maximum of max_tasks chunks, and maps the chunks in parallel across the provided task_pool. One task is spawned in the task pool for every chunk.

If max_tasks is None, this function will attempt to use one chunk per thread in task_pool.

The iteration function takes the index of the chunk in the original slice as the first argument, and the chunk as the second argument.

Returns a Vec of the mapped results in the same order as the input.

§Example
let task_pool = TaskPool::new();
let mut counts = (0..10000).collect::<Vec<u32>>();
let incremented = counts.par_splat_map_mut(&task_pool, None, |_index, chunk| {
  let mut results = Vec::new();
  for count in chunk {
    *count += 5;
    results.push(*count - 2);
  }
  results
});

assert_eq!(counts, (5..10005).collect::<Vec<u32>>());
§See Also

ParallelSlice::par_splat_map for mapping immutable slices. ParallelSliceMut::par_chunk_map_mut for mapping when a specific chunk size is desirable.

Object Safety§

This trait is not object safe.

Implementors§

§

impl<S, T> ParallelSliceMut<T> for S
where T: Send, S: AsMut<[T]>,