1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: Apache-2.0
//! scope — parallel slice reduction with safe short-lived borrows.
//!
//! `go_lib::scope` works exactly like `std::thread::scope`: goroutines spawned
//! inside the closure can borrow data from the enclosing *goroutine's* stack
//! frame because the scheduler guarantees every spawned goroutine finishes
//! before `scope` returns. No `Arc`, no channels, no `.clone()` required for
//! shared read-only data.
//!
//! `go_lib::run` requires a `'static` closure, so data that needs to be shared
//! is defined inside that closure (or moved in). `scope` then lets helper
//! goroutines borrow slices of it — the lifetime is enforced at compile time,
//! not at runtime.
//!
//! ```sh
//! cargo run --example scope
//! ```