参数传递

1
2
[dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
use std::future::Future;

async fn compare(x: i32, y: i32) -> bool {
    x > y
}

async fn example<F, Fut>(f: F)
where
    F: FnOnce(i32, i32) -> Fut,
    Fut: Future<Output = bool>,
{
    println!("{}", f(3, 2).await);
}

#[async_std::main]
async fn main() {
    example(compare).await;
}

输出结果:

1
true