Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

when I using this command cargo build to compile the rust project, shows error like this:

➜  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() {
   |       ^^

this is my fn function look like:

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

I have already tried to add the tokio micro in the main.rs like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#[macro_use]
extern crate tokio;

the problem still did not solved, why did this happen? what should I do to fixed this problem?

>Solution :

You shouldn’t use both #[rocket::main] and #[tokio::main], since the first does strictly more then the second – tokio::main just starts the runtime, rocket::main does the same and also configures it according to the Rocket configuration.

Just use the #[rocket::main] only, and everything should work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading