4 ms·
> The error in the Go snippet is that "v" is a single memory location shared throughout the loop. In Rust this is not true. However, the same concept applies
by tatterdemalion 10y ago
> The error in the Go snippet is that "v" is a single memory location shared throughout the loop.
In Rust this is not true. However, the same concept applies - say it was a variable from outside the loop. In that case, you would get a clear compile time error about moving the value into the thread's closure more than once.
A similar error would apply if you iterated over a container by reference (instead of by value).