繁体   English   中英

编译 rust 项目时,function 声明中缺少 `async` 关键字

[英]the `async` keyword is missing from the function declaration when compile rust project

当我使用这个命令 cargo build 编译 rust 项目时,显示如下错误:

➜  reddwarf-admin git:(main) ✗ cargo build
   Compiling reddwarf-admin v0.1.0 (/Users/xiaoqiangjiang/source/reddwarf/backend/reddwarf-admin)
error: the `async` keyword is missing from the function declaration
  --> src/main.rs:48:7
   |
48 | async fn main() {
   |       ^^

这是我的 fn function 看起来像:

#[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),
    };
}

我已经尝试在main.rs中添加 tokio micro,如下所示:

#[macro_use]
extern crate tokio;

问题还是没有解决,为什么会这样? 我应该怎么做才能解决这个问题?

你不应该同时使用#[rocket::main]#[tokio::main] ,因为第一个比第二个更严格 - tokio::main 只是启动运行时rocket::main也一样根据 Rocket 的配置进行配置。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM