pub struct Scope<'scope> { /* fields omitted */ }
Represents a fork-join scope which can be used to spawn any number of tasks. See scope()
for more information.
Spawns a job into the fork-join scope self
. This job will
execute sometime before the fork-join scope completes. The
job is specified as a closure, and this closure receives its
own reference to the scope self
as argument. This can be
used to inject new jobs into self
.
Nothing. The spawned closures cannot pass back values to the
caller directly, though they can write to local variables on
the stack (if those variables outlive the scope) or
communicate through shared channels.
(The intention is to eventualy integrate with Rust futures to
support spawns of functions that compute a value.)
let mut value_a = None;
let mut value_b = None;
let mut value_c = None;
rayon::scope(|s| {
s.spawn(|s1| {
value_a = Some(22);
s1.spawn(|_| {
value_b = Some(44);
});
});
s.spawn(|_| {
value_c = Some(66);
});
});
assert_eq!(value_a, Some(22));
assert_eq!(value_b, Some(44));
assert_eq!(value_c, Some(66));
The scope
function has more extensive documentation about
task spawning.
Formats the value using the given formatter. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static