4 ms·
There’s no implicit behavior here. It won’t compile if you don’t explicitly move the string into the closure.
by nynx 4y ago
There’s no implicit behavior here. It won’t compile if you don’t explicitly move the string into the closure.
- nyanpasu64 4y agoThe implicit behavior is that using a string moves it into the closure, and does compile even without `move || {...non_copy}` (which surprised even me), whereas using an integer takes a reference, and you have to "slap on `move` to make it work".
- afdbcreid 4y agoThe surprising part is that it does not compile with `Copy`, not that it compiles with `Copy`. The rules are that if a move a necessary then it is performed. The tricky part is that move is not necessary for `Copy` types, because you can capture a reference and still get an owned value.