I have a type (Foo) that can be constructed From<T>, which - my understanding is - that T::Into<Foo> is automatically implemented for me.
I then create a trait (Function) where the idea is that I can use it to call a fn where the arguments adhere to Foo::Into<Arg> and return value adheres to Foo::From<R> with some context object supplied (in the example it's just a slice) that can take Foo objects and apply them to the function and return a Foo back, where the trait handles all the conversions necessary.
However, no matter what I do I cannot seem to get the compiler to believe that the functions implement the Function trait. Am I missing something or is there an issue related to this that I haven't found yet?
Also, if there's another, better way of doing what I want, I'm open to it. Although I don't want to be using nightly and fn_tuples.
Okay, but - if I'm understanding the reply - that would also require me making a wrapper struct (and function) for N implementations, where N=number of arguments.
Your example supports a single argument Fn: Fn(A) -> R, but I'd need wrap_function2<'a, A, B, R> for a 2-argument function, and wrap_function3<'a, A, B, C, R> for a 3-argument function, etc.
I don't mind making multiple impl for Function for N arguments (or a macro to do it), and I don't mind wrapping a function, but I was really hoping to avoid having to know to wrap N functions with N different types based on N args, etc.
If you don't care about extreme runtime efficiency, You can just use function pointers with as like I mentioned at the last part. It still requires you spell oit the function signature so though.
If you want to go to the complicated path and don't want multiple wrapper function, here's a way. Playground. You can use a macro to generate most of the code.