I’ve tried to construct something that behaves similar to the Counter
example, but uses closure notation rather than implementing the call
directly. I haven’t been able to figure out a way of doing this. It
seems to always either want to capture the environment by reference,
which gives it a non-'static lifetime, or won’t capture it at all.
Is this something that is desired? I guess it feels natural to me,
coming from functional languages, to be able to construct these types
of closures. Or is the intent just to do the manual impl FnMut...
to do this kind of thing?
No, this is incorrect. move only affects capture semantics; calling semantics (&, &mut or by-value) are inferred. Because c is declared as a vector of boxes of FnMut() -> ..., the closure will be callable arbitrary number of times.
No, it won’t. There’s nothing to borrow here - the environment will be captured by value. I mean, I ran this code before posting, so I know it does not cause compilation errors)