core::par
API 参考只有英文版,由标准库源代码中的英文文档注释生成。
data-parallel helpers, on the
process's task executor (core::task): from async code on the
worker it runs on, from sync code with the caller as a guest worker.
Chunks are claimed from a shared counter by one job per worker.
Structs
ScopeSource
pub struct ScopeSpawns tasks that scope waits for.
Sourcepub fn spawn<T: Send>(§self, f: fn() -> T + Send) -> ScopeHandle<T> Run
fon the parallel pool and return a handle to join its result. Undertry_scopethe task is cancelled when the scope is; every task is joined before the scope returns. Panics if called after the scope ended.
Trait implementations 1
impl Debug for Scope
ScopeHandleSource
pub struct ScopeHandle<T>One Scope::spawned task.
Wait for the task; its result.
Trait implementations 1
impl<T> Debug for ScopeHandle<T>
TryScopeSource
pub struct TryScope<E>The Scope of try_scope.
Sourcepub fn spawn<T: Send>(§self, f: fn() throws (E) -> T + Send) -> TryScopeHandle<T, E> Scope::spawnfor a throwingf: its error cancels the scope.Whether the scope was cancelled: a long task may poll this.
Trait implementations 1
impl<E> Debug for TryScope<E>
TryScopeHandleSource
pub struct TryScopeHandle<T, E>One TryScope::spawned task.
Wait for the task: its result, its error, or (cancelled before it ran) the scope's first error.
Trait implementations 1
impl<T, E> Debug for TryScopeHandle<T, E>
Functions
for_eachSource
pub fn for_each<I: IntoIterator<Item = T>, T: Send>(iter: I, f: fn(T) + Send + Sync) Call f on every item, in parallel (order unspecified).
mapSource
pub fn map<I: IntoIterator<Item = T>, T: Send, U: Send>(iter: I, f: fn(T) -> U + Send + Sync) -> List<U> f of every item, in the items' order.
foldSource
pub fn fold<I: IntoIterator<Item = T>, T: Send>(iter: I, init: T, f: fn(T, T) -> T + Send + Sync) -> T Fold with an associative f: chunks fold in parallel, then
init and the chunk results fold in order.
reduceSource
pub fn reduce<I: IntoIterator<Item = T>, T: Send>(iter: I, f: fn(T, T) -> T + Send + Sync) -> T | none Combine the items with an associative f, as
Iterator::reduce: chunks reduce in parallel, then the chunk
results in order; none for no items.
filterSource
pub fn filter<I: IntoIterator<Item = T>, T: Send>(iter: I, pred: fn(T) -> bool + Send + Sync) -> List<T> The items pred accepts, in order.
joinSource
pub fn join<T1: Send, T2: Send>(f1: fn() -> T1 + Send, f2: fn() -> T2 + Send) -> (T1, T2) Run both at once; both results.
scopeSource
pub fn scope(f: fn(Scope)) Structured spawning: every task s.spawns has finished
when scope returns.
try_scopeSource
pub fn try_scope<E: Send>(f: fn(TryScope<E>) throws (E)) throws (E) scope whose body and tasks may throw. The first error cancels the scope: tasks that
have not started never run (a running one finishes: a sync closure has no
cancellation point), try_scope waits for the rest and throws that
error.