我正在关注Rust的async/await primer,但是在运行下面显示的hello world程序时遇到问题。
use futures::executor::block_on;
async fn hello_world() {
println!("hello, world!");
}
fn main() {
let future = hello_world(); // Nothing is printed
block_on(future); // `future` is run and "hello, world!" is printed
}
我收到错误:
1 | use futures::executor::block_on;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `block_on` in `executor`
使用此功能是否需要导入?
答案 0 :(得分:0)
如Stargateur所述,futures = { version = "0.3", features = ["compat"] }
需要添加到您的Cargo.toml依赖项中。
依存关系显示在the page following the hello world example的顶部。