Skip to main content

parallel_map

Function parallel_map 

Source
pub fn parallel_map<T, R>(
    items: &[T],
    f: impl Fn(&T) -> R + Send + Sync + 'static,
) -> Vec<R>
where T: Send + Sync + Clone + 'static, R: Send + 'static,
Expand description

Apply f to every item in items in parallel and return the results.

Uses std::thread::spawn to fan out work across chunks, then collects results in the original order.

ยงType constraints

  • T: Send + Sync โ€“ items must be shareable across threads.
  • R: Send โ€“ results must be sendable back to the main thread.
  • f: Fn(&T) -> R + Send + Sync โ€“ the closure must be thread-safe.