Just trying to understand why does following code fail with the type parameter 'R' is not constrained by the impl trait, self type, or predicates, looks pretty constrained to me.
trait Tr {}
struct W<F>(F);
// Why it doesn't work?
impl<F,I,R> Tr for W<F>
where F: FnOnce(I) -> R
{}
To work with Fns in my generic code I have to wrap them all, which is a major inconvenience:
// Workaround
struct Fun<F,I,R>(F, PhantomData<fn(I)->R>);
impl<F,I,R> Tr for W<Fun<F,I,R>>
where F: FnOnce(I) -> R
{}
In theory, one type can implement both FnOnce(I) -> R1 and FnOnce(I) -> R2 for different types R1 and R2, which would make your first implementation ambiguous.
That's what I don't understand, how single type can implement both FnOnce(I) -> R1 and FnOnce(I) -> R2 ? It can't, FnOnce is a closure or fn if nothing is captured and both arguments and return values are set for it.