rust-course/book/writing-material/posts/function_signature.md

24 lines
471 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## 函数的入参是一个async function
因为我们使用了trait bound所以不能用`Fn() -> impl Future<Output=Result<Return, sql::Error>>`的方式.
```rust
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);
}
```