from this I conclude that both clone_type and copy_type are captured by value. And that is what I would expect. However, the following doesn't compile (note that I've only added 'static bound):
I'm going to assume this is the error you meant to ask about. The compiler will capture Copy types by reference, because it prefers not to move things (without the move qualifier) if it has a choice. (Since it can create a copy from a reference, it captures a reference.)
The compiler prefers to capture a closed-over variable by immutable borrow, followed by unique immutable borrow (see below), by mutable borrow, and finally by move
I was aware of this and this makes sense
It will pick the first choice of these that is compatible with how the captured variable is used inside the closure body
but am I not using my variable by value? and why is there a difference in behavior between non-copy and copy types? and why does it depend on the 'static bound being present?
Yes, but because it's Copy, it can be captured by reference and the uses in the closure turn into *capture or such. Whether this is the best default or not could be debated,[1] but that's how it works.
The above approach relies on Copy; Rust doesn't "like" implicit clones, which is what would be required to do the analogous thing for Clone but not Copy types. (Some people do want a "capture a clone" mode or similar for things like Arc<_>.)
It captures a reference when there's not a 'static bound too. The captured reference can't be 'static because it's referencing a local variable. That's why adding 'static results in an error. Nothing changed about what got captured.
it avoids copying large Copy types but also leads to the error under discussion âŠī¸