Rest thread use external environment without move bug run successfully


#1

there is a thread1 in main, and I try to use vector of main in thread1, and didn’t use move。but it compile successfully and run.


why can I use external environment run successfully without use move.


#2

vector is moved into the closure without the move keyword. Try to print the contents of vector in the main thread.

The move keyword forces the closure to take ownership of the environment that it encloses. But the compiler will do that for you if it has to. In this case, it has to implicitly take ownership because Vec<T> is not Copy.

The first edition book has more info.