error spawn-outside-scope
spawn допустим только внутри scope { }.
What it means#
spawn is allowed lexically only inside scope { ... }, or as s.spawn(...) with s: &Scope (§8.5). Structured concurrency guarantees that child tasks finish before the scope exits. Background work belongs in node.background.
Example#
fn work() { }
fn main() {
let h = spawn work() // <- spawn-outside-scope
}error
spawn-outside-scope
How to fix#
fn work() { }
fn main() io, time {
scope {
let h = spawn work()
h.join()!
}
}Wrap the spawn in a scope block, or use node.background.spawn(...) for work that must outlive the caller.