error send
What it means#
A value can cross a task boundary (spawn, a channel, an actor message) only if its type contains no Rc, no borrows, and no non-sync cells with interior mutability (§7.3). Sharing is done through Arc<frozen T> (freeze(x)) or Arc<T> with T: sync. This is what removes data races from safe code.
Example#
fn work(xs: Rc<List<i32>>) { }
fn main() io, time {
scope {
let xs = Rc.new([1, 2, 3])
spawn work(xs) // <- send
}
}error
send
How to fix#
fn work(xs: Arc<frozen List<i32>>) { }
fn main() io, time {
scope {
let xs = freeze([1, 2, 3])
spawn work(xs)
}
}Replace Rc and borrows by owned values moved into the task, or by freeze(x) / a sync type for sharing.