Skip to main content

map

Function map 

Source
pub fn map<T, R, F>(items: &[T], f: F) -> Vec<R>
where T: Sync, R: Send, F: Fn(&T) -> R + Sync,
Available on crate features enc and parallel-encode only.
Expand description

Apply f to every item, in parallel where the budget allows.

Without the parallel-encode feature this is items.iter().map(f) and nothing is spawned, so callers need no second code path.

Results come back in the order of items however the work was scheduled, so nothing a caller decides from them – which codec was smallest, which entry goes where in a manifest – can depend on how many threads the build machine happened to offer.

Items are claimed one at a time rather than dealt out up front: assets differ in size by orders of magnitude, and a static split leaves one worker holding the only large file while the rest idle.

§Panics

Propagates a panic from f once the other workers have stopped, which is the same outcome the sequential form gives and the one a proc macro wants: an encoder that panicked has no partial result worth keeping.