mirror of https://github.com/sunface/rust-course
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
471 B
471 B
函数的入参是一个async function
因为我们使用了trait bound,所以不能用Fn() -> impl Future<Output=Result<Return, sql::Error>>
的方式.
use core::future::Future;
pub async fn on_tran<F, Fut>(f: F) -> usize
where F: Fn() -> Fut, Fut: Future<Output=usize> {
f().await
}
#[tokio::main]
async fn main() {
let foo = || {
async {
8 as usize
}
};
println!("{}", on_tran(foo).await);
}