Is there any way to get this to work without having to annotate a type I'm not using?
fn main() {
test(None);
}
fn test<C: FnMut()>(callback: Option<C>) {
if let Some(c) = callback {
c();
}
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0282]: type annotations needed
--> src/main.rs:2:5
|
2 | test(None);
| ^^^^ cannot infer type for type parameter `C` declared on the function `test`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.