The captured values are moved when the closure is called, not when it's constructed#118
The captured values are moved when the closure is called, not when it's constructed#118aaronmcdaid wants to merge 1 commit intonrc:masterfrom
Conversation
|
Just intuitively: closures may be called multiple times, can they move multiple times then? |
|
four years later, I had forgotten about this PR 😀. And now I've forgotten all the context; and maybe I was wrong back then (and also now!) From the preceding sentence in the docs:
This suggests that context here is a function (in this case a closure) that can be called at most once. An example of such a function is a function that moves something each time it's called |
|
Internally, in its body, but capture takes place during creation. That's why non-moving closure binding cannot outlive whatever it references too. Contrary to C++ where lambda can bind whatever, then be passed somewhere where original instances its bind to are gone. Usually pretty nasty to debug. |
|
Feel free to close this, or ask me to close it, if it doesn't make sense. I've forgotten all the context Thanks for your feedback 😀 |
|
I can't close this, I'm not the maintainer of this repo. |
WARNING I'm a n00b to Rust, so this is likely incorrect! Please review carefully, and apologies if this is incorrect 😀.
While closures can capture some environment by moving, it's not entirely clear to me when this happens. I guess it happens when the closure is called, not when the closure is created.
Hence, I'm proposing to add a few words. I don't think this is made entirely clear elsewhere in the document.