pub fn do_thing<T, S: AsRef<str>>(s: S) {
}
fn main() {
do_thing::<i32>("hello"); //< I'd like this to work but it doesn't, Rust tells me I have to specify both
//< type parameters because I've specified one of them.
}
Reduced example here, imagine the t: T parameter is used internally in the function. Key point is that I have to explicitly specify T as e.g. ::<i32> but I would like to avoid having to specify &str for S since the compiler knows what that type is.
One possible workaround is to have a dummy parameter of type T that is just used to get the compiler to fill out that type parameter, but I'd like to avoid that if possible.
Sorry for the late reply, but I just saw this. I was confused, but indeed:
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
--> src/lib.rs:13:16
|
13 | do_thing::<i32>("hello");
| ^^^ explicit generic argument not allowed
error: aborting due to previous error
I don't understand this, and it is very counterintuitive to me. But apparently it's not allowed, even when the types are totally unrelated. That's really frustrating and make universal types much less useful.
For anyone else who might be equally confused, see here.