I've come up with a reduced example of the issue I'm facing:
My confusion stems from the fact that it works if I pass the closure in directly, without binding it to a name first, but it doesn't work if I try to pass it in via a bound name.
I can imagine this is because binding it to a name first passes in concrete lifetime parameters. However, this works - I'm able to pass the closure in via a binding: Playground
It seems like the difference is that I'm directly passing in a reference. From a few old answers on StackOverflow, I have a vague impression that having taking a reference in the closure causes the compiler to generate the
for<'_> FnOnce that's needed, but it's a bit unclear. However, in the code I'm dealing with, I can't take a reference, because I need to consume the object that's passed in. Is there any way otherwise I can convince the compiler to generate a closure that's
for<'_> FnOnce? Or is this the wrong approach?
Additionally, is there any flag I can pass to the compiler to unpretty the closure that's generated, and/or any documentation that goes into a bit more detail about the the details of the types that the compiler generates for the closure? Something a bit like what's done for C++ on CppInsights -- see here -- where the compiler-generated type is shown? Alternatively, anything I should read to get a better intuition of the generated type?
Thanks in advance.