3 ms·
> the example could have made a pure callback function that takes a mut& db param and pass thaf param to the 'do'er function. No. If you did that, you could on
by brabel 5y ago
> the example could have made a pure callback function that takes a mut& db param and pass thaf param to the 'do'er function.
No. If you did that, you could only pass functions in that took the db as a closure argument, nothing else... you're thinking about this example only, and forgetting the problem is with the general case of capturing whatever is needed for the callback to work.
- karmakaze 5y agoOk, so then the problem statement is how to do dependency injection of lifecycle references into closures. This is specific and asking quite a lot of a single entrypoint function. The closure 'at some point' (either at the end, or coordinated give then get calls) would have to transfer ownership. At this point you'd likely be better off making an interface and not a single entry/exit closure.