以下代码 ( playground ) 无法编译:
async fn wrapper<F, Fut>(func: F)
where
F: FnOnce(&i32) -> Fut,
Fut: Future<Output = ()>,
{
let i = 5;
func(&i).await;
}
async fn myfunc(_: &i32) {}
fn main() {
wrapper(myfunc);
}
Run Code Online (Sandbox Code Playgroud)
错误信息是:
error: implementation of `std::ops::FnOnce` is not general enough
--> src/main.rs:15:5
|
15 | wrapper(myfunc);
| ^^^^^^^ implementation of `std::ops::FnOnce` is not general enough
|
= note: `std::ops::FnOnce<(&'0 i32,)>` would have to be implemented for the type `for<'_> fn(&i32) -> impl std::future::Future {myfunc}`, for …Run Code Online (Sandbox Code Playgroud) rust ×1