为什么使用东京和火箭时会"the `async` keyword missing"?



编译我的Rust项目时,我得到了以下错误:

error: the `async` keyword is missing from the function declaration
--> src/main.rs:48:7
|
48 | async fn main() {
|       ^^

我的main()看起来像:

#[rocket::main]
#[tokio::main]
async fn main() {
tokio::spawn(refresh_channel_rep());
tokio::spawn(refresh_channel_article_count());
tokio::spawn(remove_low_quality_articles());
tokio::spawn(calculate_article_trend());
let launch_result = create_server().launch().await;
match launch_result {
Ok(_) => println!("Rocket shut down gracefully."),
Err(err) => println!("Rocket had an error: {}", err),
};
}

为什么会发生这种情况?我应该怎么做才能解决这个问题?

您不应该同时使用#[rocket::main]#[tokio::main],因为第一个比第二个做得更多——tokio::main只是启动运行时,rocket::main也会这样做,并根据Rocket配置进行配置。

只需使用#[rocket::main],一切都会正常工作。

相关内容

最新更新