pub struct Scope<'scope, 'env: 'scope> { /* private fields */ }Expand description
Borrowing scope for spawning parallel sub-tasks that may capture non-'static
references.
Created by scope. Each Scope::spawn call registers a job on the unified
scheduler; the scope blocks until every spawned job has completed before the
body closure returns, so borrowed data cannot escape the scope.
This is the Rayon-style scope shape, adapted to Moirai’s unified hybrid
scheduler. Unlike join, which forks exactly two branches, scope allows
an arbitrary number of sub-tasks to be spawned and joined within a single
region.
Implementations§
Source§impl<'scope, 'env: 'scope> Scope<'scope, 'env>
impl<'scope, 'env: 'scope> Scope<'scope, 'env>
Sourcepub fn spawn<F>(&self, task: F)
pub fn spawn<F>(&self, task: F)
Spawn a parallel sub-task within this scope.
The task may borrow values that outlive the scope call. The scope waits for every spawned task before returning, so borrowed data cannot escape. A task the scheduler’s admission queue turns away runs on the calling thread instead, so backpressure costs parallelism rather than the task.
§Panics
Panics if the underlying scheduler refuses to register the task, which
registration itself does not do — the failure surfaces from scope
when the scheduler is shutting down.