天天看點

012 Rust 異步程式設計,在 async 塊中使用?

示例

  • 源碼
[dependencies]
futures = "0.3"      
  • 配置檔案
use futures;

async fn foo() -> Result<(), String>{
    "foo";
    Ok(())
}

async fn func() -> Result<(), String>{

    let fut = async {
        foo().await?;
        Ok::<(), String>(()) // <- note the explicit type annotation here
        //Ok(()) // <- note the explicit type annotation here
    };

    fut.await
}

fn main() {
    let _ = futures::executor::block_on(func());
    println!("Hello, world!");

}      

繼續閱讀