I would like to take a predicate in a trait method. To keep it object safe, I don't want to use generics. I would also like to avoid using unnecessary boxing. Thus a function pointer seems really awesome.
However currently it's not at all possible to store a closure that captures some environment in a function pointer. I can completely see why we can't borrow data, but why does this not work for a closure that moves something in?
I wonder if it's just not implemented but possible, or can it not reasonably be done? It doesn't even work with things that are
Copy, like a bool. Nor with zero sized types. There is basically no way to get information in other than accessing static globals.
If I where to stick with the function pointer, users really cannot make a predicate based on any outside information, which does seem a bit to restrictive.
I feel it can be worked around for example by making the predicate an enum with variants for a boxed closure and a fn pointer. That way people don't need to pay for the boxing if they don't use it, but it's pretty convoluted. The nice thing about closures is that their syntax is concise.