相关疑难解决方法(0)

如何等待一个盒装未来的结果?

use futures::{future, Future};

fn test() -> Box<dyn Future<Output = bool>> {
    Box::new(future::ok::<bool>(true))
}

async fn async_fn() -> bool {
    let result: bool = test().await;
    return result;
}

fn main(){
    async_fn();
    println!("Hello!");
}
Run Code Online (Sandbox Code Playgroud)

操场

错误:

use futures::{future, Future};

fn test() -> Box<dyn Future<Output = bool>> {
    Box::new(future::ok::<bool>(true))
}

async fn async_fn() -> bool {
    let result: bool = test().await;
    return result;
}

fn main(){
    async_fn();
    println!("Hello!");
}
Run Code Online (Sandbox Code Playgroud)

future rust async-await

12
推荐指数
2
解决办法
3781
查看次数

标签 统计

async-await ×1

future ×1

rust ×1