Closure capture confusion

Is this intended behaviour? I find it confusing that implementing Copy prevents automatic capture by value.

Closures not marked with move will only ever perform a move if the value is moved inside the closure. Since drop(v) performs a copy, not a move, it doesn't move the value into the closure.

1 Like

Why the distinction between copy and move in this particular case? If I write move before the closure, it doesn't move the i32 it creates a copy.

Well, the type is Copy. All operations that would normally be a move are turned into a copy when the type is known to be Copy.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.