Suppose I have a library routine, call it foo, that does something useful and requires a sqlite query to do its job. This is another instance of my old problem of preparing a sqlite query once for multiple uses. One Scheme-ish technique I’d like to use in Rust, if possible, is to write a foo_init that prepares the needed query and returns a closure, created in the same scope as the variable holding the prepared statement that captures the statement (the closure probably wants to be of the ‘move’ variety). The caller can then assign the closure to a variable named foo and call foo as needed.
The problem is that closures don’t have identifiable types, so what is the return type of foo_init? I’m guessing the return type wants to be a generic, constrained to have closure characteristics? Is there a trait that describes closureness?