Specify Generics with a generic closure

Say I have a function of:

fn blah<Type, Ret, F>(cb: F) -> Ret
where
    F: FnOnce(&mut Big<Complicated, Noisy<Type>>) -> Ret, {...}

I can call it like blah(|t: &mut Big<Complicated, Noisy<Type>>| ...), but that's a whole lot to type out at a whole lot of call sites.

Is there any way I could call it like blah::<AType>(|t| ...) somehow instead? Currently this is causing E0107 because not all the generic type arguments are defined, and I could easily define Type and Ret, but F is untypeable (as far as I know) as it's a closure. This example is distilled down to a simple one that still demonstrates the issue.

This code demonstrates the issue but it doesn't show the complexity of the type that would have to be typed in every closure (it's a rather long type...), this is just a minimized example:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f970913e2e98ea21a382140513f78f24

I do apologize if I missed an obvious thread here but I attempted searching to no avail, I might be missing some vital keywords to add to the search. Links would be amazing!

You can use _ to force a type to be inferred.

how_to_call::<u32, _, _>
1 Like

How did I not think to try that, that works even with the gnarly type I have to deal with, the first entry being explicitly stated was all it needs then! Thanks much for clearing my brain fog @RustyYato!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.