The following block is library code; I can't edit it:
struct Container<F> {
f: F,
}
fn wrapped<F, T>(f: F) -> Container<F>
where
F: FnMut() -> T,
{
Container { f }
}
I want a wrapper function that specializes T
:
fn return_10() -> u32 {
10
}
fn wrapper<F>() -> Container<F>
where
F: FnMut() -> u32,
{
wrapped(return_10)
}
fn main() {
wrapper();
}
(For the sake of simplicity, I used u32
in the code above, but in reality I want to use a trait. I'm hoping that this doesn't matter.)
It doesn't work:
error[E0308]: mismatched types
--> src/main.rs:20:13
|
20 | wrapped(return_10)
| ^^^^^^^^^ expected type parameter, found fn item
|
= note: expected type `F`
found type `fn() -> u32 {return_10}`
Why can't Rust infer that T = u32
? Am I supposed to not do this?