Skip to content

Conversation

@aaronmcdaid
Copy link

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.

@michalfita
Copy link

Just intuitively: closures may be called multiple times, can they move multiple times then?

@aaronmcdaid
Copy link
Author

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:

then the closure will have a FnOnce type.

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

@michalfita
Copy link

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.

@aaronmcdaid
Copy link
Author

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 😀

@michalfita
Copy link

I can't close this, I'm not the maintainer of this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants