This is a well-written blog entry by @nikomatsakis that shows how to avoid “borrowing too much” in closures and ending up with borrowck conflicts. This is a theme that comes up fairly often in this forum and some folks will find this useful.
8 Likes
The "block-enclosed-closure" (let's abbreviate to BEC) approach works well and the blog post contains information that I find quite useful.
Still, I do hope that in the longer-term borrowck
can make this unnecessary.
I first encountered something similar here:
https://github.com/rust-unofficial/patterns/blob/master/idioms/pass-var-to-closure.md
The blog linked above is well written with a lot better description of what's going on.